0

This regex, /\[([^]]+)\]\((((?:https?|ftp):\/\/)?.*?)\)/gm, works fine in PCRE and Python, but not so much in javascript.

Why not? How do I fix it?

1 Answer 1

1

Escaping ] inside [...] will make it work in Javascript:

\[([^\]]+)\]\((((?:https?|ftp):\/\/)?.*?)\)
     ^^
Sign up to request clarification or add additional context in comments.

2 Comments

Interesting, is Javascript just more picky or is there a reason the designers chose the need for escaping?
@Justin808, I don't know the reason behind. Some regular expression engines are smart enough to handle that, others are not. For another example: Some regular expression complain about {abc}, others don't complain and just match {abc} literally.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.