首页 > 技术文章 > 正则表达式中?=、?<=、?!、?<! 的使用

hehuiqiong 2021-01-19 10:26 原文

?=、?<=的使用举例

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

 

推荐阅读