in reply to Make a variable safe for a regex.
Quote everything that could be a metacharacter before using the variable: s/(\W)/\\$1/g
There's also quotemeta, but I've been using the above pattern for years.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Make a variable safe for a regex.
by Anno (Deacon) on Feb 25, 2007 at 22:55 UTC | |
by diotalevi (Canon) on Feb 26, 2007 at 00:47 UTC | |
by Anno (Deacon) on Feb 26, 2007 at 08:32 UTC |