Question

I have such input string:

left/1234567890

regular expression:

(left(?<=/)[0-9]{10}?)

I want to get such result: 1234567890. But it doesn't work.

Although, the next input string:

/1234567890

with the next regular expression:

((?<=/)[0-9]{10}?)

get result as expected: 1234567890.

Was it helpful?

Solution

This is because you did not include left into your lookbehind:

((?<=left/)[0-9]{10}?)

In your first example, you match left then the regex engine's 'pointer' is between t and /, so your lookbehind cannot match, because the regex engine has not passed the slash yet.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top