i have a string:
var a = '<<<<<<<br>>>>>>>>'
I want to replace: <
with <
and >
with >
, but I don't want to replace <>
if it is the <br>
tag. So, I'm doing this
a.replace(/<(?!br>)/g, '<').replace(/>(?<!<br)/g, '>')
first replace is working, but the second is not.
Javascript doesn't support lookbehinds so your expression is not valid.
For opening braces:
<(?!\/?\w)
For closing braces:
\B>
\\B
denotes a non-word boundary.
JS:
> a.replace(/<(?!\/?\w)/g, '<').replace(/\B>/g, '>')
< "<<<<<<<br>>>>>>>>"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.