felix001
felix001

Reputation: 16711

1 or zero instances within regex

I have a regex expression (below) but how do I restrict this to one 1 instance or no instances of [. -:].

if re.match("[0-9a-fA-F]{2}([. -:]?[0-9a-fA-F]{2}){%d}$" % x, self.input_value):

Thanks,

Upvotes: 1

Views: 203

Answers (1)

Jim Deville
Jim Deville

Reputation: 10672

? on a group makes it optional, which would be 1 or 0.

Edited to remove the explicit version

Upvotes: 7

Related Questions