Home > OS >  Capturing the digit in a new line after whitespace
Capturing the digit in a new line after whitespace

Time:02-01

The string we have right now is: DB GOALS: DISADVANTAGED BUSINESS ENTERPRISE - 6.0% PROPOSALS ISSUED 9 FUND TOTAL , , 0 TOTAL NUMBER OF WORKING DAYS 30

NUMBER OF BIDDERS  4   ENGINEERS EST      1,674,885.00  AMOUNT OVER
 177,014.00         PERCENT OVER EST 10.57
PROGRAM ELEMENTS

I am using the pattern (AMOUNT OVER|AMOUNT UNDER)[\n\r\s] (?:^|\s)(?=.)((?:0|(?:[1-9](?:\d*|\d{0,2}(?:,\d{3})*)))?(?:\.\d*[0-9])?)(?!\S) but it does not capture

AMOUNT OVER
 177,014.00

in the text. I suspect it is because of the whitespace before 177,014.00 because it works when we remove the whitespace.

Is there a way to capture it as it is? Thanks so much!

Here is the regex101.com link for reference.

CodePudding user response:

You might simplify the pattern a bit to:

\b(AMOUNT (?:OVER|UNDER))\s ((?:\d{1,3}(?:,\d{3})*(?:\.\d\d)?))(?!\S)

Note that [\n\r\s] can be written as \s

Regex demo

  • Related