• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 51
  • Last Modified:

Help with RegEx

I need a pattern string to edit a 10-character field having its first two characters equal to 'AA', 'AB' or 'AC', and the remaining eight characters numeric.  I don't know the RegEx "language", and don't know where to start.  Can anyone help?
0
petekipe
Asked:
petekipe
2 Solutions
 
Bill PrewCommented:
I would use the following:

^(?:(?:AA)|(?:AB)|(?:AC))[0-9]{8}$

Open in new window

Tested here:



»bp
0
 
Rgonzo1971Commented:
Hi,

or simply
^A[ABC]\d{8}$

Open in new window

REgards
0
 
Radek BaranowskiFull-stack Java DeveloperCommented:
[ABC]{2}[0-9]{8} would be the simplest I guess.

future reference: https://regexr.com/
0
 
Bill PrewCommented:
Just to inform my solution, I assumed that AA, AB, and AC were just examples, and that the real world case would be a number of combinations of two characters...

Also make sure you start and end the pattern with ^ and $ respectively, so that things like "XXAB00000000" or "AB000000000" don't pass.  Unless the input field involved is limited to 10 characters on input by the UI...


»bp
0
 
petekipeOwnerAuthor Commented:
Thanks for your help on this Bill!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now