将JavaScript正则表达式转换为C# [英] Convert JavaScript Regex to C#

查看:123
本文介绍了将JavaScript正则表达式转换为C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将以下Regex语句转换为C#?

How can I convert the following Regex statement into C#?

Match match = Regex.Match(line.Trim(), @"/^[A-Za-z-.]+([,;]\s?[A-Za-z-.]+)*$/", RegexOptions.IgnoreCase);
if (match.Success)
    //do something

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

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; Jack, Doe

请建议。

推荐答案

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

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

这篇关于将JavaScript正则表达式转换为C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆