Definitive XML Schema

Definitive XML Schema

(pwalmsley@datypic.com)

ISBN: 0132886723

2nd edition, , Prentice Hall PTR.

Chapter 9: Regular expressions

Book examples

Example 9-1. A simple type with a pattern
<xs:simpleType name="ProductNumberType">
  <xs:restriction base="xs:string">
    <xs:pattern value="\d{3}-[A-Z]{2}|\d{7}"/>
  </xs:restriction>
</xs:simpleType>
Table 9-1. Using normal characters
Regular expressionMatching stringsNon-matching strings
a a b
a|b|c a, b, c abc
Table 9-3. Using character references
Regular expressionMatching stringsNon-matching strings
a&#x20;z a z az
a&#x20;*z az, a z, a z, a z a *z
PB&amp;J PB&J PBJ
Table 9-4. Using the wildcard escape character
Regular expressionMatching stringsNon-matching strings
a.z aaz, abz, a2z az, abbz
a..z aaaz, abcz, a12z az, abz
a.*z az, abz, abcdez a b
a\.z a.z abz
.*abc.* abc, xxxabc, abcxxx, xxxabcxxx xxx
.*abc abc, xxxabc abcxxx, xxxabcxxx
abc.* abc, abcxxx xxxabc, xxxabcxxx
Table 9-6. Using single-character escapes
Regular expressionMatching stringsNon-matching strings
1+2 12, 112, 1112 1+2
1\+2 1+2 12, 1\+2
1\++2 1+2, 1++2, 1+++2 12
Table 9-8. Using multi-character escapes
Regular expressionMatching stringsNon-matching strings
a\dz a0z, a1z az, adz, a12z
a\s*z az, a Š z axz
Table 9-10. Using category escapes
Regular expressionMatching stringsNon-matching strings
\p{Lu} A, B, C a, b, c, 1, 2, 3
\P{Lu} a, b, c, 1, 2, 3 A, B, C
\p{Nd} 1, 2, 3 a, b, c, A, B, C
\P{Nd} a, b, c, A, B, C 1, 2, 3
Table 9-12. Using block escapes
Regular expressionMatching stringsNon-matching strings
\p{IsBasicLatin} a, b, c â, ß, ç
\P{IsBasicLatin} â, ß, ç a, b, c
Table 9-13. Specifying a list of characters
Regular expressionMatching stringsNon-matching strings
[abc]z az, bz, cz abz, z, abcz, abc
[\p{Lu}\d]z Az, Bz, 1z, 2z az, bz, cz, A1z
Table 9-14. Specifying a range
Regular expressionMatching stringsNon-matching strings
[a-f]z az, fz z, abz, gz, hz
[0-9a-fA-F]z 1z, az, Bz z, gz, Gz, 1aBz
[&#x0020;-&#x007F;]z az, bz, cz âz
Table 9-15. Combining characters and ranges
Regular expressionMatching stringsNon-matching strings
[0-9pqr]z 1z, 2z, pz, rz cz,dz, 0sz
[p-r\d]z 1z, 2z, pz, rz cz,dz, 0sz
Table 9-16. Negating a character class expression
Regular expressionMatching stringsNon-matching strings
[^ab]z cz, dz, 1z az, bz
[^\d]z az, bz, cz 1z, 2z, 3z
[^1-3a-c]z dz, 4z 1z, az
Table 9-17. Subtracting from a character class expression
Regular expressionMatching stringsNon-matching strings
[a-z-[c]]z az, dz, ez, zz cz
[a-z-[cd]]z az, ez, zz cz, dz
[a-z-[c-e]]z az, zz cz, dz, ez, 1z
[^a-z-[123]]z 4z az, 3z, zz
Table 9-18. Using parenthesized regular expressions
Regular expressionMatching stringsNon-matching strings
(ab)*z z, abz, ababz az, bz, aabbz
(ab|cd)z abz, cdz abcdz, z
(a+b)*z z, abz, aabz, abaabz az, abbz
([a-f]x)*z z, axz, bxfxfxz gxz, xz
(\db)*z z, 1bz, 1b2bz 1z, bz
Table 9-20. Using quantifiers
Regular expressionMatching stringsNon-matching strings
abz abz az, abbz
ab?z az, abz abbz
ab*z az, abz, abbz, abbbz, ... a1z
ab+z abz, abbz, abbbz, ... az
ab{2}z abbz abz, abbbz
ab{2,}z abbz, abbbz, abbbbz, ... az, abz
ab{2,3}z abbz, abbbz az, abz, abbbbz
a[b-d]+z abz, abdz, addbccdddz az, aez, abez
a\p{Nd}+z a1z, a11z, a234z az, abcz
a(bc)+z abcz, abcbcz, abcbcbcz, ... az, abz, acbz
Table 9-21. Branches, expressions and parentheses
Regular expressionMatching stringsNon-matching strings
true|false true, false trufalse
tru(e|f)alse trufalse true, false
yes|no|maybe yes, no, maybe yenoaybe
(a|b)c|d ac, bc, d c, ad
Datypic XML Schema Services