手机
当前位置:查字典教程网 >编程开发 >正则表达式 >java 字符串匹配函数
java 字符串匹配函数
摘要:去掉字符串中匹配的字符串复制代码代码如下:/***去掉字符串中匹配的字符串**@authorzhujie*@returnStringrege...

去掉字符串中匹配 的字符串

复制代码 代码如下:

/**

* 去掉字符串中匹配 的字符串

*

* @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 字符串匹配函数】相关文章:

JS使用正则去除字符串最后的逗号

java正则表达式验证函数

JS 正则表达式的位置匹配

php 正则 不包含某字符串的正则表达式

[asp]匹配网址的正则

PHP下ereg实现匹配ip的正则

DW 查找某字符串前的所有字符的正则表达式

JS正则表达式获取字符串中特定字符的方法

javascript中基于replace函数的正则表达式语法

JavaScript基于正则表达式的数字判断函数

精品推荐
分类导航