in reply to Re: \1, \2, \3, ... inside of a character class
in thread \1, \2, \3, ... inside of a character class

\1 can capture much more than a single character, so, it can't be used inside a character class because it doesn't represent a character, but a string

It's not a problem, see perlretut

/[\]c]def/; # matches ']def' or 'cdef' $x = 'bcr'; /[$x]at/; # matches 'bat', 'cat', or 'rat' /[\$x]at/; # matches '$at' or 'xat' /[\\$x]at/; # matches '\at', 'bat, 'cat', or 'rat'

Replies are listed 'Best First'.
Re^3: \1, \2, \3, ... inside of a character class
by gmpassos (Priest) on Aug 13, 2004 at 01:18 UTC
    Ok, what you want is \1 working as a group of chars. Well, we can't, but you can use some complexer code:
    $var = "abXaaabbbc" ; $var =~ s/(..)X(??{"[$1]+"})/${1}#/ ; print "$var\n" ;
    Output:
    ab#c

    Graciliano M. P.
    "Creativity is the expression of the liberty".