Browse - Programming Tips - How do I protect a string that is going to be used in a regular expression?

Date: 2012oct2
Language: perl, php, Java

Q.  How do I protect a string that is going to be used in a regular expression?

A.  In perl:

$ok_for_pattern = quotemeta($s);
In php:
$ok_for_pattern = quotemeta($s);
In Java:
String ok_for_pattern = Pattern.quote(s);