js 正则 macth 获取两个特殊符号之间的字符串

正则:

/^([^\特殊符号1]+)(\特殊符号2)/

案例1

我想要获取 - 和 = 之间的内容

let str = '-ooo=+eee'
for(let i = 0; i < str.length ; i++) {
	let tem = str.substring(i)
    console.log(tem.match(/^([^\-]+)(\=)/))
}

结果:

 案例2

我想要获取 < 和 > 之间的内容

let str = 'tt<div>ooiii'
for(let i = 0; i < str.length ; i++) {
	let tem = str.substring(i)
	console.log(tem.match(/^([^\<]+)(\>)/))
}

j结果

猜你喜欢

转载自blog.csdn.net/A88552211/article/details/125162920