Match whole string in regex

ⅰ亾dé卋堺 提交于 2021-02-05 05:36:46

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!