MokiNex
MokiNex

Reputation: 889

Regular expression to extract string text

this my Regexp:

 ?\b(Fwd:)|\[(.*?)\] ?

any help will be gratefully received.

Thanks a lot.

Upvotes: 1

Views: 120

Answers (1)

dippas
dippas

Reputation: 60573

Try using replace with this regex: /^.*?\[.*?]\s*/

Explanation:

  • ^ asserts position at start of the string

    • .*? matches any character (except for line terminators)
    • *? Quantifier — Matches between zero and unlimited times, as few times as possible, expanding as needed (lazy)
    • \[ matches the character [ literally (case sensitive)

      • .*? matches any character (except for line terminators)
      • *? Quantifier — Matches between zero and unlimited times, as few times as possible, expanding as needed (lazy)
    • ] matches the character ] literally (case sensitive)
    • \s* matches any whitespace character (equal to [\r\n\t\f\v ])
    • * Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)

var str = "Fwd: [ProQuest Alert] test fwd:TestFwd: test2fwd: fwd:test3";
str = str.replace(/^.*?\[.*?]\s*/, ' ');
console.log(str)

Upvotes: 1

Related Questions