It makes no sense that your third regex would work but the previous two would not. Can you prove that this happens by posting a runnable code snippet with data that demonstrates the behavior?

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:

$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 -> $_";
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).

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:

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'
Getting around this issue is what Unicode::Normalize is all about.

In reply to Re: Regex question by graff
in thread Regex question by hnn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.