Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
ECMAScript (JavaScript)

/
^\[(?!\^)(.*)\]: <?((?:[a-zA-Z]\:|\\\\[^\/\\:*?"<>|]+\\[^\/\\:*?"<>|]+|\.{1,2})(?:\\[^\/\\:*?"<>|]+)+(?:\.[^\/\\:*?"<>| ]+)|(?:\.{1,2}|~){0,1}(?:(?:\/|\\)(?:[a-zA-Z0-9._-])*)+|\w+:(?:\/?\/?)[^\s>]+)>?(?:\n? +["'(](.*)["')])?(?: \{(.*)\})?
/
gm

Description

Matches Windows & POSIX absolute and relative paths, Windows UNC paths, URIs, and optionally image titles or classes:

[my label 1]: /foo/bar.jpg "My title, optional" {.class} [my label 2]: ~/foo/bar.png "My title, optional" [my label 3]: /foo/bar.jpg 'My title, optional' [my label 4]: ~/foo/bar.png "My title, optional" [my label 5]: https://fsf.org (The free software foundation) [my label 6]: C:\path\to\image.jpg "image title" [my label 7]: ..\path\to\image.png "image title" {.class} [my label 8]: \unc.server.tld.country\path\to\file.ext "image title" {.class}

Will not match references [^reference]:

Submitted by Matt Jolly <Matt.Jolly@footclan.ninja> - 3 years ago