1

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 ******"

  • ```/(Reference)+......[1-9]/g``` should work. It might not be best its just what I know, essentially it finds the group of reference and then gets the next 6 digits – MysticSeagull Feb 07 '22 at 07:55
  • https://stackoverflow.com/questions/273141/regex-for-numbers-only Regex regex = new Regex(@"^\d$"); – faragh47 Feb 07 '22 at 08:50

1 Answers1

0

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);
        }
    }
}
Jan
  • 42,290
  • 8
  • 54
  • 79