到 Google 资讯主页   
EasyJF首页   资料   源码   软件    论坛   网站    
   使用帮助    
    该信息为本站MyRSS系统缓存内容,部分图片及附件有可能无法正常使用.easyjf.comexpert.blogjava.net无关,不对该信息负责.通过http://www.blogjava.net/JafeLee/archive/2007/12/10/166811.html访问该信息的原始内容.
页面功能  【加入收藏】 【推荐给朋友】 【字体:  】 【关闭】   
Java 正则表达式 (3) -- Quantifiers
作者:Jafe 来源:expert.blogjava.net  发布时间:2007-12-11 10:57:54.6


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



Jafe 2007-12-10 22:35 发表评论

 
相关文章
 
页面功能  【加入收藏】 【推荐给朋友】 【字体:  】 【关闭】   


EasyJF.com 2006 隐私政策 使用EasyJF前必读