Angie
Angie

Reputation: 21

Match row number prior at start of string

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

Answers (1)

Xiddoc
Xiddoc

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 number

Upvotes: 1

Related Questions