Regular Expressions 101

Community Patterns

Element's Attribute Value in XML (simple)

4

Regular Expression
PCRE (PHP <7.3)

/
<child\s+[^<]*?attr2=[\'\"](?<value>[^<]*?)[\'\"]
/
g

Description

Simple regular expression for extracting attribute value of the element in XML-string. Attribute value should be in quotes.

Submitted by Nikita Danilov - 10 years ago