问题
I have string for example: hasan عمرانی.
I want to match persian chars for the whole string. I mean if the string is not entirely persian the regex doesn't match any character.
I have this pattern so far:[\x{0600}-\x{06FF}\s]+. but it matches عمرانی.
It must not match any of the string.
please help me to provide a pattern. Thanks.
回答1:
You can add ^ at the beginning of your expression and $ at the end, to try to match from the beginning to the end of the string being searched.
^[\x{0600}-\x{06FF}\s]+$
Tested it and it works on Regex101
回答2:
You can use \p{Old_Persian} property instead of range:
^\p{Old_Persian}+$
来源:https://stackoverflow.com/questions/19448231/match-whole-string-in-regex