Not easily, because you would need to match punctuation and other odd characters. It would be nice to have a way to match any character.
Rule 9: Wild Card
The period .
matches any one character except
end-of-line.
Regular Expression | Matches |
---|---|
. | any one character except "end of line" |
b.t | bat, bbt, bct, bdt, ..., bAt, b$t, b7t, ... |
b.t. | baty, bbtx, bctq, bdt, ..., bAtY, b$t5, b7tk, ... |
So, to match a string of any five characters, use .....
.
(Quantifiers, explained at the end of this chapter, enable
a more elegant way to do this.)
If you want to specifically match a period (or decimal point) and nothing else, use \.
For example [0-9]+\.[0-9]+
matches
012.34
but not
012W34.
Write a regular expression that matches any three character string that starts with M.