JavaScript跟着指定字符串的正则表达式|RegExp ?= 量词

JavaScript RegExp 对象


定义与用法

?=n 量词匹配任何其后跟着指定字符串 n 的字符串。


语法格式

new RegExp(” regexp(?= n)”)

或者

/ regexp(?= n)/


示例代码

对其后紧跟 “all” 的 “is” 进行全局搜索:

var str="Is this all there is"; 
var patt1=/is(?= all)/g;

下面被标记的文本显示了表达式获得匹配的位置:

Is this all there is

亲自试试


浏览器支持

参数Google ChromeInternet ExplorerFirefoxSafariOpera
?=YesYesYesYesYes

所有主要浏览器都支持 ?= 量词


JavaScript RegExp 对象


相关