-1

We are implementing a feature in our web application that reads email subjects and checks the subject for a certain string containing an ID so that we can match incoming emails to projects in our application.

A subject may look like this:

OVE.com: Purchase Confirmation (2007 Subaru Impreza Wagon 2.5i JF1GG61677G808577 PEDDLE LLC)

Where (2007 Subaru Impreza Wagon 2.5i JF1GG61677G808577 is a dynamic part.

I need to identify the string of 17 digits (i.e. JF1GG61677G808577) from email subject.

7
  • Is it always 17 digits? What's the pattern of these confirmation codes?
    – Tah
    Jan 27, 2016 at 6:11
  • yes, it is always 17 digit. @TahTatsumoto Jan 27, 2016 at 6:17
  • Is there a pattern? Otherwise you might want to consider parsing instead.
    – Tah
    Jan 27, 2016 at 6:19
  • Yes, it follows a particular pattern based on input. Jan 27, 2016 at 6:21
  • Is it only digits? In your example you have letters and digits. If there can be digits and letters - is always uppercase letters? If only digits this pattern should work: \d{17}, if uppercase letters and digits: [\dA-Z]{17}. Jan 27, 2016 at 6:23

1 Answer 1

2

this is the sample snippet,

string strRegex = @"[A-Z0-9]{17}";

Regex myRegex = new Regex(strRegex, RegexOptions.None);
string strTargetString = @"OVE.com: Purchase Confirmation (2007 Subaru Impreza Wagon 2.5i JF1GG61677G808577 PEDDLE LLC)";

foreach (Match myMatch in myRegex.Matches(strTargetString))
{
  if (myMatch.Success)
  {
    // Add your code here
  }
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.