Positive Lookbehind question
-
Hello. I'm trying to understand why '(?<=a)[1-9]+' works with "a556" but 'F(?<=a)[1-9]+' doesn't work with "Fa556". Thanks!
I would suggest reading up on lookbehinds @ Advanced Regex Tutorial—Regex Syntax[^] . You see the expression (?<=) can be used both as lookbehind before the match and lookbehind after the match. The second regex, due to the "F" being first in the expression means it finds a "F", then attempts to look for an "a" before the "F" which does not fit your example text. So this is a lookbehind after the match, your first regex was a lookbehind before the match. You should put the "F" together with the "a" inside the lookbehind. Maybe you didn't for some reason known only to you. Since you have provided very little context for the 2 expressions and examples I can't help any further currently. Terry
-
I would suggest reading up on lookbehinds @ Advanced Regex Tutorial—Regex Syntax[^] . You see the expression (?<=) can be used both as lookbehind before the match and lookbehind after the match. The second regex, due to the "F" being first in the expression means it finds a "F", then attempts to look for an "a" before the "F" which does not fit your example text. So this is a lookbehind after the match, your first regex was a lookbehind before the match. You should put the "F" together with the "a" inside the lookbehind. Maybe you didn't for some reason known only to you. Since you have provided very little context for the 2 expressions and examples I can't help any further currently. Terry
Hello and thank you very much for your reply. Firstly i have to read the article you have mentioned and then we can talk again. But i believe this
You see the expression (?<=) can be used both as lookbehind before the match and lookbehind after the match.
is the most important thing that i didn't know. Can you choose if (?<=) will be treated as before or after only ??? (i will found out after reading the article :)