I need a regex that only allows these numbers and checks if a tripple occurs, how would I do that? (For Java)
>Solution :
I’d use the following pattern which you can try out here.
^[3469]*(333|444|666|999)[3469]*$
| Token | Explanation |
|---|---|
^ |
Start at the beginning of the line |
[3469]* |
Match 3, 4, 6, or 9 zero or more times |
(333|444|666|999) |
Match a triple |
[3469]* |
Match 3, 4, 6, or 9 zero or more times |
$ |
Stop at the end of the line |