22
1
using System;
2
using System.Text.RegularExpressions;
3
4
public class Program
5
{
6
public static void Main()
7
{
8
string text="AB4000-01-433593-1-1";
9
// ^ start of word match any character A-Z or 0-9 until you hit a dash, then match any character except a dash. Capture in group 1
10
string regEx = @"^([A-Z,0-9]+-[^-]+)";
11
12
Regex r = new Regex(regEx, RegexOptions.IgnoreCase);
13
Match m = r.Match(text);
14
if(m.Success)
15
{
16
Console.WriteLine(m.Groups[0]);
17
}
18
19
}
20
}
21
22
Cached Result
Hello, welcome to THE BIG TACO
What´s your name?
>
What´s your name?