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?
Answer
You can find the explanation in Pattern Javadoc:
Unicode scripts, blocks, categories and binary properties are written with the
\pand\Pconstructs 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.
No comments:
Post a Comment