?=、?<=的使用举例

var str = "XXXX            (程序员)";

var newStr,regExp;

regExp = /(?<=().*(?=))/;

newStr = str.match(regExp)

console.log(newStr);//程序员

 

==============================

exp1(?=exp2):查找 exp2 前面的 exp1。

(?<=exp2)exp1:查找 exp2 后面的 exp1。

exp1(?!exp2):查找后面不是 exp2 的 exp1。

(?<!exp2)exp1:查找前面不是 exp2 的 exp1。

参考:https://www.runoob.com/regexp/regexp-syntax.html

 

posted on 2021-01-19 10:26  Qionghuihe  阅读(2078)  评论(0编辑  收藏  举报