Regular Expressions 101

Community Patterns

1...34567...735

Xml parser

-4

Regular Expression
PCRE (PHP <7.3)

/
<([^\/> ]+)\s*([^>]*)\s*(?:\/>|>(.*)<\/\1>)
/
g

Description

Captures TagName, attributes and value in seperate groups.

Apply same pattern on capture group #3 (using recursion) to parse entire xml!

Apply regex defined in teststring to capture group #2 to parse all the attributes for the current tag.

Submitted by veryanonymous - 8 years ago