php专区

 首页 > php专区 > 正则表达式 > JS 正则表达式中小括号的应用_正则表达式

JS 正则表达式中小括号的应用_正则表达式

分享到:
【字体:
导读:
          在正则表达式中小括号的应用种类比较多,差别也很大...

主要使用的有下面三种:

1.  (...)

Grouping. Group items into a single unit that can be used with *, +, ?, |, and so on. Also remember the characters that match this group for use with later references.

2. (?:...)

Grouping only. Group items into a single unit, but do not remember the characters that match this group.

3.

(?=pA positive lookahead assertion. 或

(?!p)  A negative lookahead assertion.

 

用于测试的字符串:url(skins/default/images/index/default.png)

红色字符为匹配上的结果

第一种,用于普通分组,能记住匹配该分组的字符串,并且可以在以后通过1的方式来引用所匹配到的分组

       eg: (/)匹配url(skins/default/images/index/default.png)

           (/)default1匹配url(skins/default/images/index/default.png)

 

第二种,用于分组,不记录匹配该分组的字符串

       eg: (?:/)default匹配url(skins/default/images/index/default.png)

 

第一、二两种方式匹配的结果里都包含有该分组匹配到的结果,在例子中是"/default"中的"/"

 

第三种,只用于确定位置,最终结果里并不包含该括号匹配到的结果

       eg:  (?!/)default匹配url(skins/default/images/index/default.png)

       eg:  default(?=/)匹配url(skins/default/images/index/default.png)

分享到:
JS 正则表达式的位置匹配_正则表达式
http://regexpal.com/ 上面这个网站可以用于在线检测JS的正则表达式语法 除了熟知的几个固定字符表示位置: ^ : Match the beginning of the string and, in multiline searches, the beginning of a line. $ : Match the end of the string and, in multiline searches, the end of a line. \b:  Match a word...
正则表达式 传智播客学习_正则表达式
有了一点点小小成就,五子棋游戏的基本功能已经实现的差不多了,还需要进行部分代码优化,期待明天的到来,因为明天我就可以实现我一个梦想,那就是晚上自己开发的游戏,呵呵!学在其中,乐在其中!下午实在有些腰酸背痛,决定就近去爬山,经过商议决定去百望山森林公园,真的是好久没锻炼了,才两百多米的山爬完回来累的不...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……