in reply to Re: regex problem with metachars
in thread regex problem with metachars

Thanks for your reply but, but by using \Q it also would put a splash in front of any escaped character such as "\t". The same goes for quotemeta().

Replies are listed 'Best First'.
Re: Re: Re: regex problem with metachars
by sgifford (Prior) on Nov 07, 2003 at 18:47 UTC

    That's because \t is a regex metacharacter. If you only want to escape some metacharacters, you'll need to figure out which ones.

    If you want to escape all metacharacters beside backslash, something like:

    s/([^A-Za-z_0-9\\])/\\$1/g;
    should do it.
Re: Re: Re: regex problem with metachars
by tedrek (Pilgrim) on Nov 07, 2003 at 18:53 UTC

    If the delimiter will always be one character then you can assume anything longer than 1 character is a escape sequence like "\t". So you just call quotemeta() on delimiters with a length of 1.

    HTH

    Tedrek

      That's one I haven't thought of. I try that out. The delimiter should never be more than 1 character.

      Thanks!