Ok so I know there are some Regex questions out here on lookahead and lookbehind, but I haven't found some anwsers, to my interior questions, that I can easily relate to (...oh well).
So here's how I understand Regex lookahead and lookbehind!
Lookaheads/Lookbehinds (LA/LB) :
LA/LB preceding main Regex
(?=IF_YOU_FIND_WHAT_IS_HERE)START_MATCHING_WHAT_IS_HERE (?!IF_YOU_DO_NOT_FIND_WHAT_IS_HERE)START_MATCHING_WHAT_IS_HERE
LA/LB succeeding main Regex
START_MATCHING_WHAT_IS_HERE(?=UNTIL_THIS IS_NOT TRUE) START_MATCHING_WHAT_IS_HERE(?!UNTIL_THIS IS_NOT TRUE)
Ok so for the second part ( succeeding ), I'm really not sure and I would appreciate some rewriting of the above notations or some thumbs up for my excellent understanding (oh yeah).
So back on earth, as I understand it, after each character it matches in the "main" Regex...
- Positive lookahead : it checks if what lies ahead still matches with the lookahead part.
- Negative lookahead : it checks if what lies ahead still doesn't match the lookahead part.
- Positive lookbehind : it checks if what has been matched still matches the lookbehind part
- Negative lookbehind : it checks if what has been matched still doesn't match the lookbehind part.
Now, for the SRLC section (Super Regex Lookout Combos)
Let's look at this Regex
(?<=REGEX_1)(?<!REGEX_2((MAIN_REGEX(?<!REGEX_3))(?=REGEX_4)))
My strategy in approching this would be, well, in some cases, we could combine REGEX_1 and REGEX_2. If that was the case, we would have :
(?<=REGEX_C)((MAIN_REGEX(?<!REGEX_3))(?=REGEX_4))
C for : Combined
Essentially, what I understand is that :
- REGEX_C must succeed first in order to for the MAIN_REGEX starts matching
- Then, the MAIN_REGEX starts matching character-by-character
- Immediately after a positive-match, REGEX_3 analyses the global match.
- Next after is the REGEX_4, who will look ahead to see if all is good.
- Then we start over from 2 and try matching the next character.
- *Of course, if any REGEX fails, the global match is reseted.
I have no clue, if what I wrote is accurate haha. It's to0 messy when I want to try it out. Most of the time I succeed by trial and errors, but I would like to have somes clarifications so I can get it on my first try. Boom
Thanks for your replies!