Predefined shorthand character classes

As we have seen from the preceding examples, certain character classes, such as digits [0-9] or word characters [0-9A-Za-z_], are used in most regex patterns. The Java language, like all regular expression flavors, provides convenient predefined character classes for these character classes. Here is the list:

Shorthand Class Meaning Character Class
d A digit 0-9 [0-9]
D A non-digit [^d]
w A word character [a-zA-Z0-9_]
W A non-word character [^w]
s A whitespace character, including line break [ fx0B]
S A non-whitespace chacracter [^s]
h A horizontal whitespace character [ xA0u1680u180eu2000-u200au202fu205fu3000]
H A non-horizontal whitespace character [^h]
v A vertical whitespace character [ x0Bf x85u2028u2029]
V A non-vertical whitespace character [^v]
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.170.134