java正则表达式(四)
2012-10-15 21:16
363 查看
四、非匹配
在正则表达式中,我们往往需要在字符串中进行非匹配,这时,就要通过^进行匹配条件限制,^的常见入门用法如下:
[^a-z] 条件限制在非小写a to z范围中一个字符
[^A-Z] 条件限制在非大写A to Z范围中一个字符
[^a-zA-Z] 条件限制在非小写a to z或大写A to Z范围中一个字符
[^0-9] 条件限制在非0 to 9范围中一个字符
[^0-9a-z] 条件限制在非0 to 9或a to z范围中一个字符
代码示例如下:
在正则表达式中,我们往往需要在字符串中进行非匹配,这时,就要通过^进行匹配条件限制,^的常见入门用法如下:
[^a-z] 条件限制在非小写a to z范围中一个字符
[^A-Z] 条件限制在非大写A to Z范围中一个字符
[^a-zA-Z] 条件限制在非小写a to z或大写A to Z范围中一个字符
[^0-9] 条件限制在非0 to 9范围中一个字符
[^0-9a-z] 条件限制在非0 to 9或a to z范围中一个字符
代码示例如下:
public class RegExp { private Pattern patt; private Matcher matcher; public boolean squareReg(String regStr,String regex){ return this.commonRegExp(regStr, regex); } private boolean commonRegExp(String regStr,String regex){ boolean wildcard_Res=false; patt=Pattern.compile(regex); matcher=patt.matcher(regStr); wildcard_Res= matcher.find(); return wildcard_Res; } } public class TestRegExp { public static void main(String[] args) { RegExp re=new RegExp(); boolean wildcard_Res=false; wildcard_Res=re.squareReg("tcn", "t[^aoe]n"); System.out.println(wildcard_Res); //输出:wildcard_Res=true }
相关文章推荐
- java正则表达式提取字符串中的数字
- java中的正则表达式
- java正则表达式
- 正则表达式Pattern学习笔记(Java)
- Java基础_正则表达式
- java学习笔记之正则表达式
- Java中正则表达式使用方法详解
- 如何使用Java自带的正则表达式
- java正则表达式文档
- java---正则表达式(4)
- java正则表达式剔除HTML注释
- 【java学习】java正则表达式
- Java基础:正则表达式regex
- Java正则表达式测试用例
- 黑马程序员-java正则表达式
- java 正则表达式 每个构造字符代表什么意思(合集(全))
- 《剑指offer》 面试题53 :正则表达式匹配 Java
- java学习笔记001之正则表达式贪婪型、勉强型和占有型p299
- 利用正则表达式获取特定文件(如java class)并对其进行处理(如代码统计)
- JAVA正则表达式的匹配机制