in reply to Re: Regexes and backslashes
in thread Regexes and backslashes

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

Replies are listed 'Best First'.
Re^3: Regexes and backslashes
by AnomalousMonk (Archbishop) on Feb 16, 2011 at 04:08 UTC

    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