Steven Levithan (2012-03-23T19:37:35.000Z)
Erik Corry wrote:
> In perl the recommended version is
>
> text.replace(/([^a-zA-Z0-9])/g, "\\$1")

For the record, most languages with modern regular expressions include a 
built in method for this.

For instance:

* Perl: quotemeta(str)
* PHP: preg_quote(str)
* Python: re.escape(str)
* Ruby: Regexp.escape(str)
* Java: Pattern.quote(str)
* C#, VB.NET: Regex.Escape(str)

-- Steven Levithan
forbes at lindesay.co.uk (2014-03-24T17:49:44.380Z)
For the record, most languages with modern regular expressions include a 
built in method for this.

For instance:

* Perl: quotemeta(str)
* PHP: preg_quote(str)
* Python: re.escape(str)
* Ruby: Regexp.escape(str)
* Java: Pattern.quote(str)
* C#, VB.NET: Regex.Escape(str)