Text Processingflags: g

Markdown Image

Matches Markdown image syntax ![alt](url).

Try it in RegexPro →

Available in

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("!\\[([^\\]]*)\\]\\(([^)]+)\\)", "g");
const input = "![logo](https://example.com/logo.png)";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

Pattern

regexengine-agnostic
!\[([^\]]*)\]\(([^)]+)\)   (flags: g)

Raw source: !\[([^\]]*)\]\(([^)]+)\)

How it works

`!\[([^\]]*)\]` captures the alt text inside brackets. `\(([^)]+)\)` captures the URL in parentheses.

Examples

Input

![logo](https://example.com/logo.png)

Matches

  • ![logo](https://example.com/logo.png)

Input

![](image.jpg) and ![alt](pic.gif)

Matches

  • ![](image.jpg)
  • ![alt](pic.gif)

Common use cases

  • Markdown rendering
  • Image extraction
  • Link validation

Related patterns