Negation of a regular expression in a Pattern
Raffaello Giulietti
raffaello.giulietti at oracle.com
Mon Aug 12 13:34:28 UTC 2024
I'm not sure what's unclear in "any character except a, b, or c" or "any
character except one in the Greek block".
A line terminator is neither 'a' nor 'b' nor 'c', nor is it in the Greek
block.
Your example works the same in JDK 8, 11, 17, 21, 22, with or without
the additional MULTILINE or DOTALL flags.
(BTW, if you look carefully, the example in the Stack Overflow
discussion you are referring to builds a matcher over a string that does
_not_ contain any line terminator.)
As documented (and implied by the name), DOTALL refers to the pattern "."
Similarly, MULTILINE refers to the "^" and "$" boundary matchers.
If you feel the doc is incorrect, you might consider filing a bug report
https://bugs.java.com/bugdatabase/
On 2024-08-11 11:42, Olivier Cailloux wrote:
> Dear list,
>
> The Pattern Javadoc <https://docs.oracle.com/en/java/javase/22/docs/api/
> java.base/java/util/regex/Pattern.html> does not specify whether “Any
> character” includes line terminators in “Any character except |a|, |b|,
> or |c| (negation)” ([^abc]) or “Any character except one in the Greek
> block (negation)” (\P{InGreek}), or whether it depends on DOTALL or
> MULTILINE being set.
>
> As a result, it seems to me impossible from the doc to deduce, for
> example, whether the Pattern "[^a]" will match a line terminator
> (spoiler alert: it does <https://onecompiler.com/java/42nuaa4bd>). This
> discussion <https://stackoverflow.com/questions/64383917/> illustrates
> the confusion.
>
> Would an addition to the doc be considered?
>
More information about the core-libs-dev
mailing list