After going through the comments, it appears that using regex may not be the most suitable approach for your task, but you are determined to make it work. Your requirement seems to involve validating a comma-separated string starting at 20,000, where each subsequent part of the number consists of 3 digits. Here is a possible regex solution:
^(?:[2-9]\d|[1-9]\d\d|[1-9],\d{3})(?:,\d{3})+$
You can test this regex pattern in an online demo.
^
- Marks the start of the string.
(?:
- Opens the first non-capture group.
[2-9]\d
- Matches a digit between 2 and 9 followed by any digit.
|
- Or.
[1-9]\d\d
- Matches a digit between 1 and 9 followed by two digits.
|
- Or.
[1-9],\d{3}
- Matches a digit between 1 and 9 followed by a comma and three digits.
)
- Closes the first non-capture group.
(?:
- Opens the second non-capture group.
,\d{3}
- Matches a comma followed by three digits.
)+
- Closes the second non-capture group and allows repetition at least once.
$
- Marks the end of the string.
Alternatively, you could use lookaheads, like so:
^(?=.{6,})(?!1.{5}$)[1-9]\d?\d?(?:,\d{3})+$
Test this alternative pattern in the online demo.
^
- Marks the start of the string.
(?=.{6,}
- Positive lookahead for at least 6 characters.
(?!1.{5}$)
- Negative lookahead for a sequence of 1 followed by 5 characters until the end of the string.
[1-9]\d?\d?
- Matches a digit between 1 and 9 followed by up to two optional digits (can also be written as [1-9]\d{0,2}
).
(?:
- Opens the second non-capture group.
,\d{3}
- Matches a comma followed by three digits.
)+
- Closes the non-capture group with repeating at least once.
$
- Marks the end of the string.