How to check persian character format in regex
本问题已经有最佳答案,请猛点这里访问。
如何对所有 utf8 字符使用正则表达式?
例如我想通过正则表达式检查这种格式:
| 1 | [1][???? ??????] | 
我使用 ////w 来检查波斯字符,但它不起作用:
| 1 | ^(//[1//])(//[//w+//])$ | 
我也用过这个:
| 1 | ^(//[1//])(//[//u0600–//u06FF//])$ | 
那我该怎么做呢?
感谢您的帮助
你可以这样使用:
| 1 | ^(//[1//])(//[[?-?//s]+//])$ | 
你快到了。您只需要在字符类中包含范围 
| 1 | ^(//[1//])(//[[//u0600–//u06FF//s]+//])$ | 
演示
| 1 2 3 4 5 6 7 | String input = @"[1][???? ??????]"; Regex rgx = new Regex(@"^(//[1//])(//[[//u0600-//u06FF//s]+//])$"); foreach (Match m in rgx.Matches(input)) { Console.WriteLine(m.Groups[1].Value); Console.WriteLine(m.Groups[2].Value); } | 
输出:
| 1 2 | [1] [???? ??????] | 
IDEONE
正则表达式怎么样
| 1 | ^(//[1//])//[[//p{L}//s]+//]$ | 
示例:http://regex101.com/r/cU1nQ8/1
- 
//p{L} 匹配来自任何语言的任何类型的字母
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/269544.html
