Yes.
A space character can be part of a string.
A regular expression that describes a set of strings must
include any space characters the strings might contain.
The regular expression a x
describes the set that consists of just one string,
a x as above.
The regular expression ax
describes the set that consists of just one string,
ax without a space.
A string can begin (and can end) with one or several space characters. For example, here is a regular expression that starts with two spaces (this might be hard to see):
twoSpace
The quote marks are not part of the regular expression.
They are used here to show the leading spaces.
(However, in a Java program, a regular expression is given as a String
literal and
must be surrounded by quote marks.)
To match a tab character, use \t
in the regular expression.
To match a newline character, use \n
.
(These will not work with this chapter's regular expression applet, however.)
Chapter 9 shows how to match characters other than the usual alphanumeric ones.
(Review: ) Can an automaton transition be labeled with several characters?