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