Linus Oleander
Linus Oleander

Reputation: 18137

Match [ABC DEF](http://google.com)

I'm trying to match the following string, without success.

I've this so far.

/\[([^\]]+)(\([^\)]+)/

It's the last part that won't work (\([^\)]+).

In other words;

var meta = "[ABC DEF](http://google.com)"

This is what I want.

["ABC DEF", "http://google.com"]

Anyone knows why it won't work?

Upvotes: 1

Views: 75

Answers (1)

pimvdb
pimvdb

Reputation: 154898

You missed the ending ]. Also, ) doesn't need to be escaped in a character class. Thirdly, you could add the trailing ), and finally you should not put the literal ( inside (...) because you don't want it to be in the matches array.

meta.match(/\[([^\]]+)]\(([^)]+)\)/)
                      ^  ^  ^

Upvotes: 5

Related Questions