For example, when I run the following lines of perl code, I get the same output for both tries, and in both cases, the replacement works as expected:
I'm using hex notation for the accented letter, just to avoid potential encoding issues with the script itself. Depending on whether or not STDOUT is set to use utf8 protocol, the accented letter â in the output will be either the two-byte utf8 sequence (0xC3 0xA2) or a single byte (0xE2).$x="b\xe2r.a\xe2.bar"; $_=$x; s/[a\xe2][a\xe2]/\xe2/; print "first try: $x -> $_"; $_=$x; s/[a\xe2]{2}/\xe2/; print "second try: $x -> $_";
So I'm expecting that between your first two regexes and the third one, something else changed in addition to the regex -- e.g. the data may have been different somehow.
Bear in mind that it's possible for two strings to be different in terms of character content, but produce the same result when displayed correctly in a browser or terminal window:
Getting around this issue is what Unicode::Normalize is all about.binmode STDOUT, ":utf8"; print "\xe2\n"; # 'a' with circumflex accent (as a single character) print "a\x{0302}\n"; # 'a' followed by 'COMBINING CIRCUMFLEX ACCENT'
In reply to Re: Regex question
by graff
in thread Regex question
by hnn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |