I find this script very useful for learning and testing
regexs, but I think there may be a bug in AHK RegEx Tester v2.1
Setup: (without quotes)
- Haystack := "sfsdfsdfabcd"
- Needle := "^.*+(?<=abcd)"
RegEx Tester reports no match.
However this code
Code:
Haystack := "sfsdfsdfabcd"
Needle := "^.*+(?<=abcd)"
fp := RegExMatch(Haystack,Needle,out)
msgbox, [%fp%]`n[%out%]
reports the match at position 1 with %out% = "sfsdfsdfabcd"% (as expected).
Any chance of getting this fixed (or explained)?
-- rickly
pcre man page wrote:
Possessive quantifiers can be used in conjunction with lookbehind
assertions to specify efficient matching at the end of the subject
string. Consider a simple pattern such as
abcd$
when applied to a long string that does not match. Because matching
proceeds from left to right, PCRE will look for each "a" in the subject
and then see if what follows matches the rest of the pattern. If the
pattern is specified as
^.*abcd$
the initial .* matches the entire string at first, but when this fails
(because there is no following "a"), it backtracks to match all but the
last character, then all but the last two characters, and so on. Once
again the search for "a" covers the entire string, from right to left,
so we are no better off. However, if the pattern is written as
^.*+(?<=abcd)
there can be no backtracking for the .*+ item; it can match only the
entire string. The subsequent lookbehind assertion does a single test
on the last four characters. If it fails, the match fails immediately.
For long strings, this approach makes a significant difference to the
processing time.