using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; public class Test { public static void Main() { var pattern = @"/(?\w+)(?:@(?\S+))?(?(?s).*)"; var text = "/ping@mybot arg1 arg2"; var match = Regex.Match(text, pattern); if (match.Success) { Console.WriteLine(match.Groups["Command"].Value); Console.WriteLine(match.Groups["Target"].Value); Console.WriteLine(match.Groups["Args"].Value); } } }