<(?<nodeName>[a-zA-Z][-a-zA-Z0-9_]*)(?<attributes>(?:s*[a-zA-Z_:!0-9,][-a-zA-Z0-9_:%."'`;(]*(?:s*=s*(?:(?:"[^"]*")|(?:'[^']*')|{{[^>}]*}}|[^>]+|w*))?)*)s*(/?)>
This above regex trying to match the tagName and attributes.
<span class='Utils.showtt("{{getI18n('zr.ratings.reviews.client.review.tag', getCrmModuleInfo('Accounts', 'true'))}}")'>
but getting infinite loop since quotes mismatched in this input. Is there any way to throw error or prevent infinite loop.
2
Answers
try this regex it will match entire attribute irrespective of quotes.
Regex is the wrong tool for parsing HTML. Instead use a DOM Parser — like
DOMParser
.Note that your input string is not valid HTML: the attribute value is closed by the second quote. That quote should be escaped in the context of an attribute value. As you have several single quotes, it might be better to enclose the attribute in double quotes and escape the double quotes. So for instance, the input could be valid like this:
Example of using
DOMParser
: