On Wed, 27 Feb 2002, W  P wrote:
> I have a CGI script which takes two strings. It searches for the first
> string in a file, replacing it with the second one.  This file isn't
> really important, more for fun, so I'm not too worried about people
> deleting the whole file if they actually type out the contents as the
> first string.  However, I would like for things like . and \w to
> search for those string literals, rather than for any character or any
> word character, respectively.  Is there some function or capability
> which escapes all special characters in a string before it is passed
> to a regular expression?

To escape the '\w' just preprend another '\'.
To escape the '.' just prepent it with '\'.

e.g., $x =~ /\\w/ searches for a single back-slash followed by "w".
      $x =~ /\./ searches for a single period.

-- 
Eric P.
Los Gatos, CA


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to