Regular expression - I have got 1 pattern that I need help with

Regular expression - I have got 1 pattern that I need help with


I want to match the following patterns:

Pattern 1: 1234567

Pattern 2: 1234567;1234567;…

The user has to enter a 7-digits string. The user can provide multiple 7-digits strings but must be delimited by semicolon (;).

What regular expression should I use in this case?


Welcome @kennethO!

What expression have you tried so far?

I tried to match string that should contains 7 digits, i.e. [0-9]{7}

But the semicolon (:wink: is optional. If the string only has 7 digits, pattern matched success. If the pattern consists of two 7-digits strings, then they should be delimited by semi-colon.
I tried various ways, but still can’t find a working regular expression.

I am not sure if this type of pattern can be matched by regular expression, but I think since there is a pattern, there should be a regular expression that can work…

Are you trying to capture each of the seven digit numbers or just validate the string only has 7 digit numbers with multiple number separated by semi-colons?

I am trying to validate each of the seven digit numbers, and each seven digit numbers must be delimited by semi-colon. If the numbers are not seven-digits (e.g. alpha-numeric), validation fails.

If the 7 digits numbers are not delimited by semi-colon (e.g. comma), validation fails.


Would the above work?

it works! you are great :slight_smile: thanks for your suggestion.