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
Post a Comment