Home > Blockchain >  regex - do not collect if formatted numbers before speific word anywhere in text string
regex - do not collect if formatted numbers before speific word anywhere in text string

Time:11-17

I do not want to match the regex if any formatted number, such as $1,000 appears anywhere before a specific word in the text string.

In this case the word to find is "expungement" - but only if there is NO formatted value before it.

So I would not want to match this string.

this is some initial text $11,000 recommends the expungement more text following

but this would be accepatable

this is some initial text expungement more text following

Thank you.

CodePudding user response:

A pattern you can use is:

^[^\$]*(?!\$[0-9,] )expungement

To explain:

  1. ^ is start of string
  2. [^$]* means match any character that is not '$', 0 or more times
  3. (?!x) means negative lookup for x. If x is found in the line, the match is negated
  4. \$[0-9,] is a literal dollar sign followed by any combination of digits and commas
  5. Your desired string at the end
  • Related