Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Java How would you create a regex that only allows numbers 3,4,6 or 9 and in the regex a sequence of numbers consisting of 3 numbers must repeat?

I need a regex that only allows these numbers and checks if a tripple occurs, how would I do that? (For Java)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading