June 20th, 2012, 04:19 PM
Regex new lines and the . character
the . character in a regular expression does not match new lines
how do i match any character, including an unknown number of new lines?
ive tried these:
none seem to work
June 20th, 2012, 04:44 PM
Normally a . will not match newline characters. You can change this in Java by passing Pattern's DOTALL constant as a flag to Pattern.compile().
Without that, your second option
should work (assuming you had to escape the backslash for a legitimate reason).
As for the other two you tried,
- [...] means a character set. Period (.) and pipe (|) lose their special meanings inside, so [.|\s] means "a period, a pipe, or whitespace".
- .|\s* will match either a single character or many whitespace characters (because the * attaches to the \s, not to the whole expression).
By the way we have a regex forum.
June 20th, 2012, 09:15 PM
YESSSS IT WORKS!!!
especially thank u for the explanation on the bracers, it was very clear