in reply to : Re: Escaping a string
in thread Escaping a string

THanks, out of interest, how would I escape using a regex.

Replies are listed 'Best First'.
Re: Re: : Re: Escaping a string
by demerphq (Chancellor) on Mar 13, 2003 at 21:49 UTC

    Frankly you got a bunch of valid answers here (zaxo for instance answered your question, but you didnt seem to grok it.) Around here we usually like to see people make some effort in their questions. Some kind of sign that we the respondants arent putting more effort into things than the questioner. Anyway,

    s/(\\\\|\\')|'/$1 ? $1 : "\\'"/ge;

    will do something like what you want. Its so confusing and strange looking because it doesnt screw up preescaped data (assuming that \\ is really a \). Theres probably cleaner nicer looking ways to do it to, but this works and came off the top of my head.

    Oh and please dont ask what/how it works. Read perlre like the rest of us did.


    ---
    demerphq


      Quoth the Annonymous Monk (emphasis added):
      THanks, out of interest, how would I escape using a regex.
      This wording tells me that he was satisfied with the original answer(s), but "for leaning's sake" wondered if there was another way. Granted, once the problem is solved you have more time to futz with it and probably should, but there you go.

      thor