java - Why does the regex \pL+\pM+ not work with English? -


why regex \pl+\pm+ not work english?

why below first example results false wherein second 1 results true?

system.out.println(charset.forname("utf-8").encode("suren")                  .ascharbuffer().tostring().matches("\\pl+\\pm+"));  system.out.println(charset.forname("utf-8").encode("स्वागत")                  .ascharbuffer().tostring().matches("\\pl+\\pm+")); 

basically need regular expression restrict unicode characters(any language in world) in string.

you want

"^[\\p{letter&}\\p{mark}]+$" 

your regex requires mark (\pm+), whereas want allow it. note anchors.

on general note: i'd recommend use long forms of unicode character properties. makes expression more readable.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -