Definitive XML Schema

Definitive XML Schema

(pwalmsley@datypic.com)

ISBN: 0130655678

1st edition, , Prentice Hall PTR.

Chapter 10: Regular expressions

Book examples

Example 10-1. A simple type with a pattern
<xsd:simpleType name="ProdNumType">
  <xsd:restriction base="xsd:string">
    <xsd:pattern value="\d{3}-[A-Z]{2}|\d{7}"/>
  </xsd:restriction>
</xsd:simpleType>
Table 10-1. Using normal characters
Regular expressionMatching stringsNon-matching strings
a a b
a|b|c a, b, c abc
Table 10-3. Using character entity 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 10-5. 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 10-7. Using multi-character escapes
Regular expressionMatching stringsNon-matching strings
a\dz a0z, a1z az, adz, a12z
a.z a1z, axz az, axxz
Table 10-9. 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 10-11. Using block escapes
Regular expressionMatching stringsNon-matching strings
\p{IsBasicLatin} a, b, c â, ß, ç
\P{IsBasicLatin} â, ß, ç a, b, c
Table 10-12. 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 10-13. 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 10-14. 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 10-15. 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 10-16. 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 10-17. Using parenthesized regular expressions
Regular expressionMatching stringsNon-matching strings
(a|b)z az, bz abz, z
(ab)*z z, abz, ababz az, bz, aabbz
(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 10-19. 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
Datypic XML Schema Services