using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"\b004010H2[127][02379](?:A[12])?\b";
string input = @"$str = ""this is the code 004010H222A1 the rest is irrelevant"";
$str = ""the random number is 004010H223A2 ** anything else is irrelevant"";
$str = ""the last lottery number 004010H220A1 ~~ the rest is irrelevant"";
$str = ""yet another random sentence 004010H279A1 the rest is irrelevant"";
$str = ""any sentence before what i want 004010H279A1 the rest is irrelevant"";
$str = ""last winning number 004010H217~~~"";
";
foreach (Match m in Regex.Matches(input, pattern))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx