网站导航网学 原创论文 原创专题 网站设计 最新系统 原创论文 论文降重 发表论文 论文发表 UI设计定制 论文答辩PPT格式排版 期刊发表 论文专题
返回网学首页
网学原创论文
最新论文 推荐专题 热门论文 论文专题
当前位置: 网学 > 设计资源 > 正则表达式 > 正文

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.

(?=p) A positive lookahead assertion. 或

(?!p) A negative lookahead assertion.

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

红色字符为匹配上的结果

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

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

(\/)default\1匹配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)

设为首页 | 加入收藏 | 网学首页 | 原创论文 | 计算机原创
版权所有 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2020 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号 常年法律顾问:王律师