关于c#:如何在正则表达式中检查波斯字符格式 | 珊瑚贝

How to check persian character format in regex

本问题已经有最佳答案,请猛点这里访问。


如何对所有 utf8 字符使用正则表达式?
例如我想通过正则表达式检查这种格式:

1
[1][???? ??????]

我使用 \\\\w 来检查波斯字符,但它不起作用:

1
^(\\[1\\])(\\[\\w+\\])$

我也用过这个:

1
^(\\[1\\])(\\[\\u0600\\u06FF\\])$

那我该怎么做呢?
感谢您的帮助


你可以这样使用:

1
^(\\[1\\])(\\[[?-?\\s]+\\])$

你快到了。您只需要在字符类中包含范围 \\u0600-\\u06FF,即匹配空格 \\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

[\\u0600-\\u06FF\\s]+ 匹配给定列表中的一个或多个字符。 – 仅在字符类中充当范围运算符。


正则表达式怎么样

1
^(\\[1\\])\\[[\\p{L}\\s]+\\]$

示例:http://regex101.com/r/cU1nQ8/1

  • \\p{L} 匹配来自任何语言的任何类型的字母

来源:https://www.codenong.com/27076600/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9090.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?