[
https://issues.apache.org/jira/browse/LANG-373?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Henri Yandell updated LANG-373:
-------------------------------
Summary: Quote regexp (was: Qutoe regexp)
> Quote regexp
> ------------
>
> Key: LANG-373
> URL: https://issues.apache.org/jira/browse/LANG-373
> Project: Commons Lang
> Issue Type: New Feature
> Reporter: Henri Yandell
> Fix For: LangTwo 1.0
>
>
> Once Lang is 1.4 dependent; add this from String Taglib's StringW (suitably
> changed for Java's syntax):
> /**
> * Quote a string so that it may be used in a regular expression
> * without any parts of the string being considered as a
> * part of the regular expression's control characters.
> */
> static public String quoteRegularExpression(String str) {
> // replace ? + * / . ^ $ as long as they're not in character
> // class. so must be done by hand
> char[] chrs = str.toCharArray();
> int sz = chrs.length;
> StringBuffer buffer = new StringBuffer(2*sz);
> for(int i=0; i<sz; i++) {
> switch(chrs[i]) {
> case '[' :
> case ']' :
> case '?' :
> case '+' :
> case '*' :
> case '/' :
> case '.' :
> case '^' :
> case '$' :
> buffer.append("\\");
> default :
> buffer.append(chrs[i]);
> }
> }
> return buffer.toString();
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.