匹配正则表达式中的整个字符串 [英] Match whole string in regex
问题描述
我有一个字符串,例如:hasan عمرانی
.我想为整个字符串匹配波斯字符.我的意思是,如果字符串不完全是波斯语,则正则表达式不匹配任何字符.
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.
到目前为止我有这个模式:[\x{0600}-\x{06FF}\s]+
.但它匹配عمرانی
.它不能匹配任何字符串.
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.
推荐答案
您可以在表达式的开头添加 ^
并在末尾添加 $
,以尝试从被搜索字符串的开头到结尾匹配.
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]+$
对其进行了测试,它适用于 Regex101
Tested it and it works on Regex101
这篇关于匹配正则表达式中的整个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!