Skip to content

Instantly share code, notes, and snippets.

@pcrov
Last active September 13, 2016 08:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcrov/a6337227c56ca5719fd7 to your computer and use it in GitHub Desktop.
Save pcrov/a6337227c56ca5719fd7 to your computer and use it in GitHub Desktop.
// XMLDecl from http://www.w3.org/TR/xml/#xmldoc
$regex = <<<'REGEX'
/
(?(DEFINE)
(?<S> [\x20\x9\xD\xA]+ )
(?<Eq> (?&S)? = (?&S)? )
)
^(?<XMLDecl>
<\?xml
(?<VersionInfo>
(?&S) version (?&Eq)
(?|
'(?<VersionNum> 1\.[0-9]+ )' |
"(?<VersionNum> 1\.[0-9]+ )"
)
)
(?<EncodingDecl>
(?&S) encoding (?&Eq)
(?|
'(?<EncName> [A-Za-z] (?:[A-Za-z0-9._] | -)*)' |
"(?<EncName> [A-Za-z] (?:[A-Za-z0-9._] | -)*)"
)
)?
(?<SDDecl>
(?&S) standalone (?&Eq)
(?|
'(?<Standalone> yes | no)' |
"(?<Standalone> yes | no)"
)
)?
(?&S)? \?>
)
/x
REGEX;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment