Reputation: 21
I need to capture line number listed in below examples.
9. X/KNOWN NUMBER - 245
10. X/KNOWN NUMBER - 123
Each line may have 3 spaces in front (for #9) or 2 spaces in front (for #10). The result I want is either 9 or 10
I have tried ^.+(?=KNOWN NUMBER)
, but my result is 9. X/ and 10. X/
.
Upvotes: 2
Views: 171
Reputation: 3628
You could try the following:
^\s+(\d+)\.
^
: Start of the line\s+
: Match spaces in front(\d+)
: Group to catch the number\.
: Match literal period .
after the numberUpvotes: 1