I am working with some java code, that has the following statement:
if (sql1.matches("(?i)^CREATE\\s+TABLE\\p{all}*")) {
// do something;
}
I have searched the regex syntax and can't find a rule that uses \\p{all}
. So what's the meaning of this expression?
To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" . You also need to use regex \\ to match "\" (back-slash).
The backslash \ is an escape character in Java Strings. That means backslash has a predefined meaning in Java. You have to use double backslash \\ to define a single backslash. If you want to define \w , then you must be using \\w in your regex.
1 Answer. That P in the syntax is for the Pattern! The association names a (sub)pattern for succeeding use in the regex. Everything is a pattern, though, in a regexp.
The Unicode all
category is added "manually" to the list of categories to match any char, including line breaks, etc.
See Java regex
source code:
map.put("all", new CharPropertyFactory() {
CharProperty make() { return new All(); }});
and then this part:
/**
* Implements the Unicode category ALL and the dot metacharacter when
* in dotall mode.
*/
static final class All extends CharProperty {
boolean isSatisfiedBy(int ch) {
return true;
}
}
All()
is used to instantiate .
with DOTALL
mode, see this part:
case '.':
next();
if (has(DOTALL)) {
node = new All();
} ....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With