匹配正则表达式中的整个字符串

编程入门 行业动态 更新时间:2024-10-23 20:25:34
本文介绍了匹配正则表达式中的整个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个字符串,例如: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

更多推荐

匹配正则表达式中的整个字符串

本文发布于:2023-10-23 13:49:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1521002.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   正则表达式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!