0

I have a C# project that requires me to capture a string value from a html stream.

The pattern I need to match is:

XXXX-abc  

Where:

XXXX = a 4 character integer  

followed by a -

abc =  a 3 character alphanumeric.  

I looked at txt2re.com and got

  string re1="(\\d)";   // Any Single Digit 1  
  string re2="(\\d)";   // Any Single Digit 2
  string re3="(\\d)";   // Any Single Digit 3
  string re4="(\\d)";   // Any Single Digit 4
  string re5="(-)"; // Any Single Character 1
  string re6="((?:[a-z][a-z]*[0-9]+[a-z0-9]*))";    // Alphanum 1

The thing I am having difficulty with is combining it into one expression instead of 6. I know I can do:

Regex r = new Regex(re1+re2+re3+re4+re5+re6,RegexOptions.IgnoreCase|RegexOptions.Singleline);

However, my OCD cringes at this method :)

1 Answer 1

1

You can use the expresion \d{4}-\w{3} 4 digits follow by - follow by 3 alphanumerical characters. Here is a good site to test and learn about the regular expresion.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.