13

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

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

Please advice.

2
  • Please clarify: how is the code you currently have not doing what you want it to? Commented May 14, 2013 at 7:44
  • 3
    I rolled this back to the revision one, because if you edit the question to include the solution from the answer, it then becomes useless. Commented Oct 27, 2015 at 15:07

1 Answer 1

37

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

Sign up to request clarification or add additional context in comments.

4 Comments

Also, the a-zs can be removed (or the IgnoreCase option), and the dash should be at the end of the character class [A-Z.-].
It does work for me here regexhero.net/tester which uses .NET Regex engine, for all of your examples. What string does it fail on?
I found my error. Was a spelling mistake. Thanks for your help!
@SoulSlayer Why was the question edited to include this answer? It's confusing when I look at this and see that the answer was already implemented in the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.