Regex to capture between paranthesis

CSharp · Console

/Program.cs

using System;
using System.Text.RegularExpressions;
					
public class Program
{
	private static Regex regex = new Regex("^.*\\((?<login>.*)\\)$", RegexOptions.Compiled | RegexOptions.ExplicitCapture);
	
	public static void Main()
	{
		Console.WriteLine(GetLogin("ZACKSON MOREIRA MORGAN (zackson.morgan)"));
		Console.WriteLine(GetLogin("ZACKSON MOREIRA MORGAN (zackson.morgan"));
		Console.WriteLine(GetLogin("ZACKSON MOREIRA MORGAN )"));
		Console.WriteLine(GetLogin("ZACKSON MOREIRA MORGAN ("));
		Console.WriteLine(GetLogin("ZACKSON MOREIRA MORGAN"));
	}
	
	private static string GetLogin(string input)
	{				
		var res = regex.Match(input);
		if(res.Success)
			return res.Groups["login"].Value;
		else
			return "No matches found";
	}
}
;