^x* vs x*$by Carl-Joseph (Scribe)
|on Aug 19, 2000 at 13:16 UTC||Need Help??|
Carl-Joseph has asked for the wisdom of the Perl Monks concerning the following question:
My friends and I have been playing around with regular expressions, and we ran into something that we haven't been able to explain.
Here is some test code that shows the "phenomena".
The above code produces the following output.
Here is why we are confused:
Why does the first pattern match after the "x". I understand that "x*" is able to match nothing, but shouldn't it match the nothing before the "x", rather than the nothing after the "x".
The reason I think it should match before the "x" is that I use the "^" assertion. Also, Camel2, p61 says:
"... any regular expression that can match the null string is guaranteed to match at the leftmost position in the string."
Also, why does the second pattern "x*$" match twice when the first pattern matched only once. It seems as though they should either both match once or both match twice.