You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using '-re' to match a regex, there is an issue regarding the used index() function and matching ^ or $.
Example (simplified, but represents the code of Example.pm:759-785
my $string = "test\r\ntest-end-test\r\nend";
my $pattern = qr/^end$/m;
if (my @matchlist = ($string =~ m/($pattern)/)) {
# match successful => the "end" at the end of the string is matched and stored in @matchlist
# but now you are using index() to determine the position... which will give you the position of the "end" string at "test-end-test", NOT the matched "end" at the end of the string
my $start = index $string, $matchlist[0];
# so in the end, $before and $after are wrong
my $before = substr $string, 0, $start;
my $after = substr $string, $start + length($matchlist[0]);
print "Before: $before\n";
print "After: $after\n";
}
String:
test
test-end-test
end
Output:
Before: test
test-
After: -test
end
Expected output:
Before: test
test-end-test
After:
The code used in v1.25 was not using index() and seems to work as expectd.
I am, too, suffering from this problem (see details below), the patched version of Expect.pm provided in this thread here above solves it for me. Is there a reason, why the patch was not considered so far? It would be greatly appreciated.
Relevant debug output, notice the unwanted residue in "After match string":
spawn id(3): Does `\r\n\r\n{master:0}\r\nroot@router> \r\n\r\n{master:0}\r\nroot@router'
match:
pattern #1: -re `(?^:[\\r\\n]+[^\\r\\n<]+[#>%] ?$)'? No.
spawn id(3): Does `\r\n\r\n{master:0}\r\nroot@router> \r\n\r\n{master:0}\r\nroot@router> '
match:
pattern #1: -re `(?^:[\\r\\n]+[^\\r\\n<]+[#>%] ?$)'? YES!!
Before match string: `\r\n\r\n{master:0}'
Match string: `\r\nroot@router> '
After match string: `\r\n\r\n{master:0}\r\nroot@router> '
Matchlist: ()
When using '-re' to match a regex, there is an issue regarding the used index() function and matching ^ or $.
Example (simplified, but represents the code of Example.pm:759-785
String:
Output:
Expected output:
The code used in v1.25 was not using index() and seems to work as expectd.
The text was updated successfully, but these errors were encountered: