Jafe Lee

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  49 随笔 :: 0 文章 :: 24 评论 :: 0 Trackbacks

1、Java 正则表达式中的Quantifiers(量词)使用来指定匹配字符出现的次数的,java api中有三种Quantifiers: greedy, reluctant, and possessive。虽然三种quantifiers的作用很相似(见下表),但是三者还是有区别的。(摘自java.sun.com

Quantifiers
 Meaning
 Greedy  Reluctant  Possessive
 X?  X??  X?+  X, once or not at all
 X*  X*?  X*+  X, zero or more times
 X+  X+?  X++  X, one or more times
 X{n}  X{n}?  X{n}+  X, exactly n times
 X{n,}  X{n,}?  X{n,}+  X, at least n times
 X{n,m}  X{n,m}?  X{n,m}+  X, at least n but not more than m times


2、几个例子(摘自 java.sun.com
  • greedy quantifiers
  • Zero-Length Matches (1)
  • Zero-Length Matches (2)
  • Zero-Length Matches (3)
  • exactly n number of times
  • at least n times
  • an upper limit
  • Capturing Groups with Quantifiers
  • Character Class with Quantifiers

posted on 2007-12-10 22:35 Jafe Lee 阅读(633) 评论(2)  编辑  收藏

评论

# re: Java 正则表达式 (3) -- Quantifiers 2007-12-12 19:17 jeasonzhao
展开代码的时候有JS错误  回复  更多评论
  

# re: Java 正则表达式 (3) -- Quantifiers 2007-12-12 20:41 Jafe
@jeasonzhao
我用firefox没什么问题啊~
其实这些在 java.sun.com上都有的,我也只是copy过来而已~  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: