Reputation:
Can you help me with this example please:
BUILTIN\s+\d{1,2}
https://regex101.com/r/w7A3H7/1
I only want to filter out the numbers after text BUILTIN
and before the x
character. Now the result also contains the word BUILTIN
, what I want to be removed.
I also can't simply use \d{1,2}x
because I must make sure it is after the second occurance of the word BUILTIN
. Thank you
Upvotes: 0
Views: 121
Reputation: 26014
You can use the following pattern:
BUILTIN\s+\K\d+(?=x)
BUILTIN
Literal substring.\s+
Match whitespace, one or more occurrences.\K
Reset operator which resets the match. \d+
Match digits. (?=x)
Positive lookahead which ensures that after the digits a x
is present.You can try it here:
If you are working with a regex flavor which does not support the reset operator, you can use:
(?<=BUILTIN\s{11})\d+(?=x)
(?<=BUILTIN\s{11})
Lookbehind for literal substring followed by 11 whitespaces.\d+
Match digits. (?=x)
Positive lookahead which ensures that after the digits a x
is present.You can try it here
Match 1
Full match 57-59 `48`
Match 2
Full match 137-138 `4`
Match 3
Full match 283-285 `24`
Match 4
Full match 363-365 `48`
Upvotes: 1