将 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 05:02:59  来源:igfitidea点击:

Convert JavaScript Regex to C#

c#javascriptregex

提问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,DoeJane;DoeJane, Doe; Hyman, Doe

Match 方法中提到的模式是我从我的 javascript 方法中选择的模式。它基本上匹配名称,例如Jane,DoeJane;DoeJane, Doe; Hyman, Doe

Please advice.

请指教。

回答by Andrey Shchekin

Remove /at the start and the end of the string.

/在字符串的开头和结尾删除。