commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell (JIRA)" <j...@apache.org>
Subject [jira] Closed: (LANG-373) Quote regexp
Date Mon, 19 Nov 2007 20:42:43 GMT

     [ https://issues.apache.org/jira/browse/LANG-373?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Henri Yandell closed LANG-373.
------------------------------

    Resolution: Won't Fix

Good point on \Q and \E. Also, there's a Pattern.quote(String) in 1.5+ so this is an unnecessary
feature.

> 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.


Mime
View raw message