Originally posted by Sunil Kumar:
I agree with Bauke.
For the regex provided by Peter. "-"(hyphen) carries a special meaning in java regex, i.e. a range. So you need to escape the - using \(forward slash) (For any reserved character you need the same)
that would mean if you want to use hyphen as a delimiter just as you used for "." (dot)
So you regex will become
Note that inside a character class, the normal regex meta character loose their "special powers". So the class:
can be written as:
because the DOT doesn't match "any character", just the '.' itself.
Also note that the hyphen is treated as a "range operator" only when NOT placed at the start or end of a character class. So there's no need to escape the hyphen when doing:
which makes it (a bit) easier to read.
[ December 27, 2008: Message edited by: Piet Verdriet ]