| Kenny McCormack 2004-05-04, 4:36 pm |
| I'm looking for a good general solution to the problem of escaping all the
"magic" characters in a string. That is, so that you can do a reg exp
match against it and not have unexpected effects from the presence of magic
characters. (Yes, I know that with the problem as stated, you might ask
"Why not just use an equality test instead of a reg exp test?" Assume
there is a good reason for doing a reg exp test [think "contains"])
I'm pretty sure I've seen a good function for this, in the examples section
of either the GAWK or TAWK distributions, but I cannot find it now
(obviously, since I am posting this...).
Here's what I have; can anyone improve on this (or point me to an
"official" solution) ?
function quot(s) {
gsub(/[]*.\\[]/,"\\\\&",s)
return s
}
|