Code:
Arrays.asList("AAAA DDDD, DDDD".split("[\\P{L}]+")).forEach(System.out::println);
Output:
AAAA
DDDD
DDDD
Please notice it's P{L}
instead of p{L}
(which means letters). I googled it but find nothing. So could any one give me some hint about that?
What is RegEx (Regular Expression) Pattern? How to use it in Java? Example Attached What is RegEx? Regular Expression is a search pattern for String. java.util.regex Classes for matching character sequences against patterns specified by regular expressions in Java. .
Regular Expression is a search pattern for String. java.util.regex Classes for matching character sequences against patterns specified by regular expressions in Java. . Dot, any character (may or may not match line terminators, read on) ? Match 1 or 0 times Java Split also an Regex example. . Match any character (except newline)
Working with regular expressions in Java is also sometimes referred to as pattern matching in Java. A regular expression is also sometimes referred to as a pattern (hence the name of the Java Pattern class). Thus, the term pattern matching in Java means matching a regular expression (pattern) against a text using Java.
Java Regex The Java Regex or Regular Expression is an API to define a pattern for searching or manipulating strings. It is widely used to define the constraint on strings such as password and email validation.
You can find the explanation in Pattern
Javadoc:
Unicode scripts, blocks, categories and binary properties are written with the
\p
and\P
constructs as in Perl.\p{prop}
matches if the input has the property prop, while\P{prop}
does not match if the input has that property.
So it's the opposite of \p
.
Simple: it's the opposite of \\p{L}
.
Essentially all "non-letters".
I couldn't find an exact reference in the API, but you can infer the suggestion from the behavior or, say, \\s
vs \\S
(which is documented there).
Edit (credit to Tunaki for having eyes)
This is actually suggested by the following statement in the documentation:
Unicode blocks and categories are written with the \p and \P constructs as in Perl.
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