I thought it may be [.\n]+ but that doesn't seem to work?
+2
A:
The dot cannot be used inside character classes.
See the option Pattern.DOTALL.
Pattern.DOTALL
Enables dotall mode. In dotall mode, the expression.
matches any character, including a line terminator. By default this expression does not match line terminators. Dotall mode can also be enabled via the embedded flag expression(?s)
. (The s is a mnemonic for "single-line" mode, which is what this is called in Perl.)
If you need it on just a portion of the regular expression, you use e.g. [\s\S]
.
Artefacto
2010-07-11 10:16:55
Arguably cleaner than `[\s\S]` would be `(?:.|\n)`. The reason that `[.\n]` doesn't work is that `.` isn't special in character classes; specifying the same thing with a literal or, `|`, works fine.
Antal S-Z
2010-07-11 12:09:14
@Antal I don't think `(?:.|\n)` is as portable since a new line in Windows is `\r\n`. Maybe `(?:.|\n|\r)`, though now the `\r` is redundant in Unix.
Artefacto
2010-07-11 12:12:30
@Artefacto: Good call. I think the usual solution is `\r?\n`.
Antal S-Z
2010-07-11 12:33:31
In Java, just do `(?s:`...`)` to enable DOTALL mode for a specific section, and stop worrying about stupid OSs.
Peter Boughton
2010-07-11 12:58:46
Or, of course, `(?s)`...`(?-s)` to toggle it on then off at those points.
Peter Boughton
2010-07-11 13:01:48