Removes the matching string from the string.
Copy codeThe Code is as follows:
/**
* Remove the matched strings from the string.
*
* @ Author zhujie
* @ Return String regex content to be replaced what is the content replaced by value String state?
*/
Public static String toRegex (String regex, String value, String state ){
Pattern p = Pattern. compile (regex );
Matcher m = p. matcher (value );
StringBuffer sb = new StringBuffer ();
While (m. find ()){
M. appendReplacement (sb, state );
}
M. appendTail (sb );
Return sb. toString ();
}
Copy codeThe Code is as follows:
Public static void main (String [] args ){
* String regex = "\ p {Lower}"; // remove the Lower-case character regex = "'"; // remove'
* Regex = "\ p {SC}"; // remove the currency symbol $ regex = "\ p {Punct}"; // remove all the symbols in it
* Regex = "\" "; // remove" regex = "<.>"; // remove the html Tag
*
* String value = "fjdks <sss> jfl 'fdk $ jfl ";
* System. out. println (toRegex (regex, value ,""));
*/
}