页面导航: 首页网络编程正则表达式 → 正文内容 java 字符串匹配

java 字符串匹配函数

发布:dxy 字体:[增加 减小] 类型:转载
java去掉字符串中匹配的字符串
去掉字符串中匹配 的字符串

/**
* 去掉字符串中匹配 的字符串
*
* @author zhujie
* @return String regex 要替换的内容 value 字符串 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();
}


public static void main(String[] args) {
* String regex = "\\p{Lower}"; //去掉里面的小写字符 regex ="'"; //去掉里面的 '
* regex="\\p{Sc}"; //去掉货币符号 $ regex="\\p{Punct}"; //去掉里面的所有的符号
* regex="\""; //去掉 " regex ="<.>"; //去掉里面的html 标签
*
* String value="fjdks<sss>jfl'fdk$$jfl";
* System.out.println(toRegex(regex,value,""));
*/
}
浏览次数:载入中... 打印本文关闭本文返回首页
·在百度中搜索关于“java 字符串匹配函数相关内容

文章评论

共有 位脚本之家网友发表了评论我来说两句

同 类 文 章
最 近 更 新
热 点 排 行