Sunday 22 December 2019

What does regex pattern "[\P{L}]+" mean in Java?





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


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...