in reply to Re^3: perl indication of end of string already matched
in thread perl indication of end of string already matched
my $str = "abc"; $str =~ m/.|$/g; # succeeds, and pos goes to 1 $str =~ m/.|$/g; # succeeds, and pos goes to 2 $str =~ m/.|$/g; # succeeds, and pos goes to 3 $str =~ m/.|$/g; # succeeds, and pos stays at 3 # Why does this behave + differently than the next regex? pos($str) is 3 for both calls $str =~ m/.|$/g; # fails and resets pos
How does the engine know that it has already succeeded with the fourth regex (when pos is already 3)? There must be some mechanism that records that internally in the regex engine. I'd like to know if that information is accessible.
FYI, I rewrite my code constantly, this issue came up during one rewrite, I have to go back and see if there's a case where it is helpful. But the question still piqued my interest. I would like to understand if the internal structure that has this information ($ matched) is accessible
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: perl indication of end of string already matched
by haukex (Archbishop) on Jun 08, 2020 at 22:37 UTC | |
|
Re^5: perl indication of end of string already matched
by AnomalousMonk (Archbishop) on Jun 09, 2020 at 00:40 UTC | |
by haukex (Archbishop) on Jun 09, 2020 at 08:29 UTC |