Definitive XML Schema
Priscilla Walmsley (pwalmsley@datypic.com)
ISBN: 0132886723
2nd edition, , Prentice Hall PTR.
Chapter 9: Regular expressions
Book examples
<xs:simpleType name="ProductNumberType"> <xs:restriction base="xs:string"> <xs:pattern value="\d{3}-[A-Z]{2}|\d{7}"/> </xs:restriction> </xs:simpleType>
Regular expression | Matching strings | Non-matching strings |
---|---|---|
a
|
a
|
b
|
a|b|c
|
a, b, c
|
abc
|
Regular expression | Matching strings | Non-matching strings |
---|---|---|
a z
|
a z
|
az
|
a *z
|
az, a z, a z, a z
|
a *z
|
PB&J
|
PB&J
|
PBJ
|
Regular expression | Matching strings | Non-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
|
Regular expression | Matching strings | Non-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
|
Regular expression | Matching strings | Non-matching strings |
---|---|---|
a\dz
|
a0z, a1z
|
az, adz, a12z
|
a\s*z
|
az, a Š z
|
axz
|
Regular expression | Matching strings | Non-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
|
Regular expression | Matching strings | Non-matching strings |
---|---|---|
\p{IsBasicLatin}
|
a, b, c
|
â, ß, ç
|
\P{IsBasicLatin}
|
â, ß, ç
|
a, b, c
|
Regular expression | Matching strings | Non-matching strings |
---|---|---|
[abc]z
|
az, bz, cz
|
abz, z, abcz, abc
|
[\p{Lu}\d]z
|
Az, Bz, 1z, 2z
|
az, bz, cz, A1z
|
Regular expression | Matching strings | Non-matching strings |
---|---|---|
[a-f]z
|
az, fz
|
z, abz, gz, hz
|
[0-9a-fA-F]z
|
1z, az, Bz
|
z, gz, Gz, 1aBz
|
[ -]z
|
az, bz, cz
|
âz
|
Regular expression | Matching strings | Non-matching strings |
---|---|---|
[0-9pqr]z
|
1z, 2z, pz, rz
|
cz,dz, 0sz
|
[p-r\d]z
|
1z, 2z, pz, rz
|
cz,dz, 0sz
|
Regular expression | Matching strings | Non-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
|
Regular expression | Matching strings | Non-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
|
Regular expression | Matching strings | Non-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
|
Regular expression | Matching strings | Non-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
|
Regular expression | Matching strings | Non-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
|