Regular Expressions 101

Community Patterns

Extract all links from HTML / Извлечь все ссылки из HTML

1

Regular Expression
PCRE2 (PHP >=7.3)

/
<a [^>]+>(?:(?!<\/a>).)+<\/a>
/
gm

Description

Extract all links from HTML including the tag itself and its contents. The content may include other tags, such as H1, img, etc.

Извлечь все ссылки из HTML включая сам тег и его содержимое. Содержимое может включать другие теги, например, H1, img и т.д.

Submitted by a.panarin - 2 months ago