in reply to Regexes and backslashes

You're first regex works fine for including a return character in a character class, you simply didn't have any return characters in your string. It helps if you print out your string that you're matching before and after you make changes to it:
$_ = "Goodbye\\; Good luck\\, and thanks for all the fish!\\\n\\\n"; print "<$_>\n"; s/\\([;,\n])/$+/g; # Does work print "<$_>\n";
However, it's also possible that you meant the string to be as it was, in which case maybe you're wanting to reeval that string and therefore turn the escaped characters into their corresponding code like the following:
$_ = "Goodbye\\; Good luck\\, and thanks for all the fish!\\n\\n"; print qq{<$_>\n}; s/(\\.)/qq{"$1"}/eeg; print qq{<$_>\n};

Replies are listed 'Best First'.
Re^2: Regexes and backslashes
by oko1 (Deacon) on Feb 16, 2011 at 01:47 UTC

    I did indeed mean the string to be as it was; it's actually text that I'm getting from an email that I want to parse. The part where I said "Ugh" was specifically because I'm not a fan of 'eval'ing arbitrary text; that's a a really, really bad idea. :)

    There are lots of ways to solve "the problem" (which isn't really a problem; I mean, two substitutions and it's done.) I was just curious to see if, given that original string - one with single backslashes in it - a capture mechanism could be constructed along the lines of what I was trying to do. At the moment, it looks like the answer is 'no' - but I hope that someone here will prove me wrong.

    -- 
    Education is not the filling of a pail, but the lighting of a fire.
     -- W. B. Yeats

      Pay particular attention to the way the  \ (backslash) character interpolates into a single-quoted string, and how many of them you need to use to get a  \\ double-backslash into the actual string (and printed).

      >perl -wMstrict -le "$_ = 'Goodbye\; Good luck\, and thanks for all the fish!\\\\n\\\\n'; print; s{ \\(.) }{$1}xmsg; print; " Goodbye\; Good luck\, and thanks for all the fish!\\n\\n Goodbye; Good luck, and thanks for all the fish!\n\n