Regex for markdown link

/\[([^\]]+)\]\(([^)\s]+)(?:\s+"([^"]*)")?\)/g

Options
Matches

Examples

Note

Group 1 is the text, group 2 the URL, group 3 the optional title.

Matches in the example

  • "[the docs](https://example.com/docs \"Docs\")"
  • "[home](/)"

Token by token

  1. \[ the character “[”
  2. ( a capturing group
  3. [^\]]+ any character except the character “]”, one or more times, as many as possible
  4. ) end of group
  5. \] the character “]”
  6. \( the character “(”
  7. ( a capturing group
  8. [^)\s]+ any character except “)” or a whitespace character, one or more times, as many as possible
  9. ) end of group
  10. (?: a group, not capturing
  11. \s+ a whitespace character, one or more times, as many as possible
  12. " the character “"”
  13. ( a capturing group
  14. [^"]* any character except “"”, zero or more times, as many as possible
  15. ) end of group
  16. " the character “"”
  17. )? end of group, whole group optionally
  18. \) the character “)”

Other patterns