Eldar Khaitov Eldar Khaitov - 1 year ago 91
Node.js Question

Regexp match smth like <a href="..."> javascript

I managed to match

<a href="http://localhost:3000/#/project/57fa46a56fd91a88201943dc">
<a href[^\>]*>

But from server comes secured information with omitted parenthesis, e.g.
&lt;a href="http://localhost:3000/#/project/57fa46a56fd91a88201943dc"&gt;
. I cannot just write
&lt;a href[^\&gt;]*&gt;
because it reacts on any charachter
, or

I can find information about matching words of one character after another but for some reason it doesn't work in negation

So, what is the way to manage it so the code look fine?

Answer Source

The best fix is probably one that fixes your server so it returns your HTML a tag with correct < and > characters, rather than the encoded &lt; &gt;.

If that's not a possibility, try:

<|(\&lt)a href... which should match < or the literal &lt (& must be escaped, lt do not need to be escaped).

Check it works on regex101.com

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download