Skip to content

Instantly share code, notes, and snippets.

@abdullahpazarbasi
Created January 30, 2017 15:32
Show Gist options
  • Save abdullahpazarbasi/979f7fb131211e10b839c69c07d73bb3 to your computer and use it in GitHub Desktop.
Save abdullahpazarbasi/979f7fb131211e10b839c69c07d73bb3 to your computer and use it in GitHub Desktop.
XML tag regular expression
$re = '/(<\s*(\w+)((?:\s+\w+(?:\s*=\s*(?:(?:"(?<=")(?:(?<=\\\\)"|[^"])*(?=")")|(?:\'(?<=\')(?:(?<=\\\\)\'|[^\'])*(?=\')\')))?)*)\s*>((?<=\>)(?:[^<>])*(?=\<))((?1))*((?<=\>)(?:[^<>])*(?=\<))<\s*\/\2\s*>)/i';
$str = '<a class="foo" style="bar: \'a\'; baz: \\"bax\\""> front
<b class="i"> inner <d attr= \'bak\\\'\\\'\'></d></b>
last
</a>';
preg_match_all($re, $str, $matches);
// Print the entire match result
print_r($matches);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment