New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Perl bug??? #384
Comments
From Dan.Reidy@wl.comScript #!/opt/perl5/bin/perl # # Output string=123ABC2222321212 string=123ABC2122321212 string=123ABC2X22321212 Daniel J. Reidy |
From @tamiasOn Mon, Aug 16, 1999 at 04:20:10PM -0400, Reidy, Dan wrote:
This is not a bug in Perl, but a misunderstanding of character classes. [^\1] matches any character other than "\1", which can also be written as Use a negative lookahead assertion instead: $string =~ /([0-9])(?!\1)(\d)\1/; If you're not certain whether something is a Perl bug, comp.lang.perl.misc HTH |
From [Unknown Contact. See original ticket]
Reidy> I am looking to find pattern like 121 232 191 or 454, but Reidy> # I expect to find 232, but I find 222 Reidy> $string =~ /([0-9])([^\1])\1/; Dan, the [...] character class RE matches each character in it literally [^\1] matches NOT 1, the \ character redundantly escapes the 1. Your RE will match any three-digit palindrome with no 1 in the middle. One solution (to be tested with perl -n) to the exercise left to the if (/([0-9])([0-9])\1/ and ($1 ne $2)) { You got to try a little harder to find a real perl bug! Adrian |
Migrated from rt.perl.org#1219 (status was 'resolved')
Searchable as RT1219$
The text was updated successfully, but these errors were encountered: