I want to find a match in a html string.
That will not be between html tags or inside them.
For example:
the word is : ue
<span color=blue>ue</span>ue<span>sdfsd</span>
so I want to find only the third match (not inside “blue”) and not between the span tags.
Thanks
You’re trying to use regular expressions to parse HTML. HTML cannot be readily, reliably processed with a regular expression on its own.
If you’re doing this on a browser, you can instead leverage the browser’s highly-optimized HTML parser.
If you want to detect the word when there’s a tag in-between (e.g., “u<hr>e”):
If you only want to detect it between things (so, your example but not “u<hr>e”):
(Both of those do case-sensitive matching.)
That does this
document.createElement.innerHTMLon the element. This property has only recently been standardized, but it’s been supported by all major browsers for a decade or so.Node#firstChild,Node#nodeType,Node#nodeValue, andNode#nextSibling.The links above are mostly to the DOM2 Core spec, most of which is supported by most browsers. Other references that can be handy: