in reply to Matching quoted variables. Cant make it work..

Thanks for the feedback, but I think that my main problem is with understanding the action of the quoting (or lack of). Some replies did state that the meta characters of the string prevent the regex from matching. I can see that is stopping the match. But what level of quoting is necessary here to prevent the meta characters from messing up the match ?

So the real issue, now, in my mind is not so much 'how regex works' but how would I use quoting to make the regex ignore the possibility that the input variables might contain a meta character, since this example is just the essence of problem and not my complete code.

  • Comment on Re: Matching quoted variables. Cant make it work..

Replies are listed 'Best First'.
Re^2: Matching quoted variables. Cant make it work..
by Melly (Chaplain) on Mar 16, 2006 at 22:54 UTC

    A previous suggestion to use

    "\Q$a\E"

    is the easiest way to avoid these kind of problems. If you want to inlclude a variable that may contain meta-characters, then \Q forces the escaping of meta-characters (i.e. puts '\' before each one). \E turns escaping off. Play with it.

    Hope that helps.

    Tom Melly, tom@tomandlu.co.uk