Ok i got this example from Regular Expression Cookbook
^(?=.{3}$).*
The regex above is use to limit the length of an arbitrary pattern
If i test again ‘aaabbb’, it completely fail
From what i understand it look for any character that precede by any character 3 in length.SO it should match ‘bbb’ but its not
One more question, should lookbehind follow this pattern x(?=x)
That is actually a lookahead assertion not a lookbehind assertion. The ^ anchors the match at the start of the string, it then asserts that the beginning of the string must be followed by 3 characters followed by the end of the string.
Edit: I should have probably mentioned that the .* at the end is then used to match those three characters since a lookahead assertion doesn’t consume any characters.