Dave’s Brain
Home
Search
Browse
Recent
Keywords
Other sites
Feedback
Sign in
Random
Crawlers
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);