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

Regular expressions for 0's that are a length that is the multiple of 2 or 3

What would be a regular expression that accepts all strings of 0’s of length k where k is a multiple of 2 or 3?

For example, it should accept '', '00', '000', '0000', '000000' and reject '0', '00000', '0000000', '00000000000'.

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

>Solution :

^((00)*|(000)*)$ should do it. It matches 0 or more instances of 00 or 0 or more instances of 000, with the ^$ making the pattern apply to the entire string instead of a substring.

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