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)
(/)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的正则表达式语法除了熟知的几个固定字符表示位置:^:Matchthebeginningofthestringand,inmultilinesearches,thebeginni
JavaScript 正则表达式之RegExp属性、方法及应用分析
使用RegExp的显式构造函数,语法为:newRegExp("pattern"[,"flags"])。使用RegExp的隐式构造函数,采用纯文本格式:/pattern/[flags]。pattern部分为要使用的正则表
javascript 手机号码正则表达式验证函数 原创
functioncheckMobile(){varsMobile=document.mobileform.mobile.valueif(!(/^1[3|4|5|8][0-9]d{4,8}$/.test(sMobile))){alert("不是完整的11位手机号或者正确的手机号前七位");document.mobile