in reply to Re: replacing variable in regex - probs with special chars?
in thread replacing variable in regex - probs with special chars?

unfortunatly the whole thing isn't used for webpages or any of the like. HTML::Template and Mason are not suited for the whole purpose of what this is doing (it's just an excerpt out of the whole thing).

I'm going to dig out my copy of the camel book and start reading, thanks for the direction!

Emanuel
  • Comment on Re: Re: replacing variable in regex - probs with special chars?

Replies are listed 'Best First'.
Re: Re: Re: replacing variable in regex - probs with special chars?
by jmuhlich (Acolyte) on Jan 30, 2003 at 20:11 UTC

    Yes, you want:

    s/\Q$complete\E/...
    because $complete has metacharacters in it. Pretty much any time you want to stick a variable in a regex, you want to use \Q...\E. The only exception is if the variable is supposed to contain a regex itself, but that can get dangerous (arbitrary perl code in regexes, etc).

    Also, maybe Template::Toolkit would be of use. It just does general text templates, making no assumptions about web apps or HTML.

Re: Re: Re: replacing variable in regex - probs with special chars?
by jmuhlich (Acolyte) on Jan 30, 2003 at 20:16 UTC