javascript - How can I match reference-style markdown links? -


i interested in using javascript find reference-style markdown links in string of text. want following:

  • [all things][things] => "things"
  • [something] => "something"

but not:

  • [o hai](http://example.com)
  • [o hai] (http://example.com)

in other words, open square bracket followed close square bracket, capturing text inside, not same followed set of parentheses.

make sense? thanks!

for example:

/(?:\[[\w\s]*\])?(\[[\w\s]*\])(?!\s*\()/  ^--------------^ - possibly first [...], ?: - non-capturing group                  ^-----------^ - followed [...]                               ^-------^ - not followed "   (" - spaces + (  > [all things][things]".match(/(?:\[[\w\s]*\])?(\[[\w\s]*\])(?!\s*\()/)[1] "[things]" > "[something]".match(/(?:\[[\w\s]*\])?(\[[\w\s]*\])(?!\s*\()/)[1] "[something]" > "[o hai](http://example.com)".match(/(?:\[[\w\s]*\])?(\[[\w\s]*\])(?!\s*\()/) null > "[o hai] (http://example.com)".match(/(?:\[[\w\s]*\])?(\[[\w\s]*\])(?!\s*\()/) null 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -