Below is my sample text
Pick Ticket 81091 Reference 109437
Issuing Date/Time 27/Jan/2022 10:19:10AM Status 35-Pick in Progress
I need to get the 6 digits number after this word "Reference". The text will be always like this "Reference ******"
Below is my sample text
Pick Ticket 81091 Reference 109437
Issuing Date/Time 27/Jan/2022 10:19:10AM Status 35-Pick in Progress
I need to get the 6 digits number after this word "Reference". The text will be always like this "Reference ******"
You might simply use
Reference\s+(\d+)$
and use the first capturing group (switch on the multiline modifier).
See a demo on regex101.com.
In C#
:
using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"Reference\s+(\d+)$";
string input = @"Pick Ticket 81091 Reference 109437
Issuing Date/Time 27/Jan/2022 10:19:10AM Status 35-Pick in Progress
";
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}