Using Regex in JS I'm trying to match all <
and >
which are not part of a specific HTML element. In the below example, I try to exclude those associated with <sup> and </sup> but my current expression still matches with > at the end of the element.
How can I also exclude the ending > of the element?
Current expression:
/(?!<\/?sup>)[<>]/gi
Almost there; the special tag can show up before or after a tag, eg using ( Demo ):
(?<!sup)[<>](?!\/?sup)
Or if you want to make it more readable: <(??\/?sup)|(?<!\/?sup)>
We could optimize this with possessive quantifiers; unfortunately, JS does not support them.
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.