将 JavaScript 正则表达式转换为 C#
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16536061/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert JavaScript Regex to C#
提问by Soul Slayer
How can I convert the following Regex statement into C#?
如何将以下 Regex 语句转换为 C#?
Match match = Regex.Match(line.Trim(), @"/^[A-Za-z-.]+([,;]\s?[A-Za-z-.]+)*$/", RegexOptions.IgnoreCase);
if (match.Success)
//do something
The pattern mentioned in the Match method is the one I picked from my javascript method.
It basically matches names such as Jane,Doe
Jane;Doe
Jane, Doe; Hyman, Doe
Match 方法中提到的模式是我从我的 javascript 方法中选择的模式。它基本上匹配名称,例如Jane,Doe
Jane;Doe
Jane, Doe; Hyman, Doe
Please advice.
请指教。
回答by Andrey Shchekin
Remove /
at the start and the end of the string.
/
在字符串的开头和结尾删除。