Webflags: g

XML Namespace Declaration

Match XML namespace declarations (`xmlns="..."` and `xmlns:prefix="..."`), capturing the prefix and URI.

Try it in RegexPro →

Available in

Pattern

regexengine-agnostic
xmlns(?::([\w\-]+))?\s*=\s*["']([^"']+)["']   (flags: g)

Raw source: xmlns(?::([\w\-]+))?\s*=\s*["']([^"']+)["']

How it works

xmlns matches the literal attribute name. (?::([\w\-]+))? optionally captures a colon-prefix (e.g. `xmlns:xlink`). \s*=\s* matches the equals with optional whitespace. ["']([^"']+)["'] captures the URI in either quote style.

Examples

Input

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">

Matches

  • xmlns="http://www.w3.org/2000/svg"
  • xmlns:xlink="http://www.w3.org/1999/xlink"

Input

<root xmlns='urn:custom'>

Matches

  • xmlns='urn:custom'

Input

<plain>

No match

Common use cases

  • XML schema migration tooling
  • SVG / SOAP message parsing
  • Namespace conflict detection
  • XML-to-JSON conversion preprocessors