Webflags: g
XML Processing Instruction
Match XML processing instructions like `<?xml version="1.0" encoding="utf-8"?>` or `<?xml-stylesheet href="..."?>`.
Try it in RegexPro →Available in
Pattern
regexengine-agnostic
<\?[\w\-]+(?:\s+[\w\-]+\s*=\s*["'][^"']*["'])*\s*\?> (flags: g)Raw source: <\?[\w\-]+(?:\s+[\w\-]+\s*=\s*["'][^"']*["'])*\s*\?>
How it works
<\? matches the literal opener. [\w\-]+ captures the PI target name. The repeating group matches optional `attr="value"` pairs. The trailing `\s*\?>` matches the closer. Works for the XML declaration and any custom processing instruction.
Examples
Input
<?xml version="1.0" encoding="UTF-8"?>Matches
<?xml version="1.0" encoding="UTF-8"?>
Input
<?xml-stylesheet type="text/xsl" href="style.xsl"?>Matches
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
Input
<root>plain</root>No match
—Common use cases
- •XML/SVG/RSS preprocessing
- •Detecting and stripping XML declarations before merging documents
- •XSLT pipeline tooling
- •Sitemap and feed validation
Related patterns
XML Namespace Declaration
WebMatch XML namespace declarations (`xmlns="..."` and `xmlns:prefix="..."`), capturing the prefix and URI.
CSS Custom Property (Variable)
WebMatch CSS custom properties (variables) like `--brand-color` or `--font-size-lg`.
Cookie Header Value
WebParse name=value pairs from an HTTP `Cookie:` header value.
CSS Class from `class=""` Attribute
WebExtract the value of a `class="..."` attribute from raw HTML, handling double or single quotes.