Name

xs:pattern

Synopsis

<xs:pattern
  id = "ID"
  value = "regular expression" >
  <!-- (xs:annotation?) -->
</xs:pattern>

The xs:pattern facet element is used to derive new simple types by specifying a regular expression against which values of the type are compared. It applies to all simple types. The schema regular-expression grammar is quite similar to that used in Perl 5.6 and later. (The big change from earlier versions of Perl is support for Unicode character class-based regular expressions.) Most strings and characters match themselves, but a few characters have special meanings, as summarized in Table 22-1. In this table, A and B are subexpressions; n and m are nonnegative integers; a, b, c, and d are all single Unicode characters; and X is a name.

Table 22-1. XML Schema regular-expression syntax

Pattern

Matches

( A )

A string that matches A

A | B

A string that matches A or a string that matches B

AB

A string that matches A followed by a string that matches B

A ?

Zero or one repetitions of a string that matches A

A *

Zero or more repetitions of a string that matches A

A +

One or more repetitions of a string that matches A

A { n,m }

A sequence of between n and m strings, each of which matches A

A { n }

A sequence of exactly n strings, each of which matches A

A { n ,}

A sequence of at least n strings, each of which matches A

[ abcd ]

Exactly one of the characters listed inside the square brackets

[^ abcd ]

Exactly one character not listed inside the square brackets

[ a-z ...

Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.