Java Reference
In-Depth Information
you start writing a new function to do that, the rest of us will just saunter over to the RegEx
Bar & Grille, order a
^Q[^u]\d+\.
. from the bartender, and be on our way.
OK, the
[^u]
means
match any one character that is not the character
u
.
The
\d+
means one
or more numeric digits. The
+
is a quantifier meaning one or more occurrences of what it fol-
lows, and
\d
is any one numeric digit. So
\d+
means a number with one, two, or more digits.
Finally, the
\.
? Well, . by itself is a metacharacter. Most single metacharacters are switched
off by preceding them with an escape character. Not the Esc key on your keyboard, of
course. The regex “escape” character is the backslash. Preceding a metacharacter like . with
this escape turns off its special meaning, so we look for a literal period rather than “any char-
acter.” Preceding a few selected alphabetic characters (e.g.,
n
,
r
,
t
,
s
,
w
) with escape turns
I have typed part of the regex as
Q[
u
and because there is an unclosed square bracket, the
Syntax OK flag is turned off; when I complete the regex, it will be turned back on. In the
second frame, I have finished typing the regex, and typed the data string as
QA577
(which
you should expect to match the
^Q[^u]\d+
, but not the period since I haven't typed it). In the
third frame, I've typed the period so the Matches flag is set to Yes.