Syntax definitions: tappable links with multiple links in a line

Does anyone else working with a syntax that makes Markdown links tappable have issues with more than one link in the same line?

Here’s the JSON I borrowed from the canonical Markdown+Links syntax:

"match": "(\\[)()(.*)(\\]\\()([^ ]*)(\\))",
      "templates": {
        "": "[[value_unencoded]]"
      "enabled": true,
      "captures": {
        "value": "5",
        "key": "2",
        "prefix": "1",
        "suffix": "6",
        "link": "3"
      "scopes": {
        "value": "text.italic",
        "key": "text.bold",
        "prefix": "markup",
        "suffix": "markup"

With two links in a line, the last url becomes the link and everything between becomes tappable.

Thought the fix might be as simple as tweaking the regex, but there’s something I’m missing between the regex and the key value assignments. So for example, this regex works to correctly parse multiple links in the same line:

"match": "(!?\\[)([^\\[]+)(\\])(\\()(\\S[^\\)]+)(\\))",

but I haven’t yet been able to make it tappable— I’d assume the “link” key should be assigned to match group 5, but no joy. I’m probably overlooking something obvious. Any pointers?

It’s not a big issue, and there are a few easy workarounds, but I’d love to understand where I’m going wrong…

That’s not the regex from the Markdown+Links I shared, but mine was also susceptible to this issue. I updated my version in the Directory. The solution is to use a less greedy match for the link title between the [ ] braces. The version you have already does this for the link itself but not for the title.

To fix your, change the (.*) to ([^\]]*) - which functionally changes “look for any character” to “look for any character until a ]”.

1 Like

Thanks Greg! Wondering where I got that original regex from now… :flushed: