0

I need a regex pattern to match this format ABC12345678:

it should start with ABC and should have preceding 8 numbers.

0

3 Answers 3

4

The pattern you're looking for is

ABC\d{8}
Sign up to request clarification or add additional context in comments.

2 Comments

You might want to anchor the regex: ^ABC\d{8}$, otherwise, depending on how the regex is used, it may match strings like ABC123456789101112....
@Bart K. +1, that might definitely be the case, depending on the desired result, which isn't very well defined.
1

Whenever I have to write a regex (which I try to avoid as much as possible), I refer to this .NET regex cheat sheet.

2 Comments

Why do you avoid regular expressions?
Because a) I'm not good at them, and b) many times there's a better solution. I'm not saying they shouldn't be used, or are never applicable, I'm just describing my behavior.
0

txt2re is a great online resource for creating regex from a string. It also generates code samples in many languages including c#.

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.