`
thrillerzw
  • 浏览: 139001 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

java正则表达式

    博客分类:
  • java
 
阅读更多

1 、异常:Horrible Exception: java.lang.ArrayIndexOutOfBoundsException: 0  

    错误:String  unitPrice=120000.00;   unitPrice.split(".")[0];   

    正确:String  unitPrice=120000.00;   unitPrice.split("\\.")[0];

    点“ . “需要转义 。预定义字符类 ,点“.”表示 任何字符(与行结束符可能匹配也可能不匹配) 

    注意|分割的时候要用"\\|"

 

    String[]    split(String regex)      根据给定的正则表达式的匹配来拆分此字符串。

    其它预定义字符类 

    \d 数字:[0-9] 

    \D 非数字: [^0-9] 

    \s 空白字符:[ \t\n\x0B\f\r] 

    \S 非空白字符:[^\s] 

    \w 单词字符:[a-zA-Z_0-9] 

    \W 非单词字符:[^\w] 

 

2 、[^abc]任何字符,除了 a、b 或 c(否定)

       [abc]a、b 或 c

 

3 、判断数字

Pattern pattern = Pattern.compile("[0-9]+");
boolean isNum = pattern.matcher(queryValue).matches();

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics