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

Time:03-05

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'.

CodePudding user response:

^((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.

  • Related