Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the meaning of "\\p{all}" in regex?

Tags:

java

regex

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?

like image 399
Pengfei Zhan Avatar asked Jul 12 '18 08:07

Pengfei Zhan


People also ask

What does \\ mean in regex?

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).

What does \\ mean in Java regex?

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.

What does P do in 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.


1 Answers

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();
    } ....
like image 95
Wiktor Stribiżew Avatar answered Oct 13 '22 19:10

Wiktor Stribiżew