Parzh from Ukraine
Parzh from Ukraine

Reputation: 9863

Why does this regexp return infinite?

Regular expression [13579]?[13579]? returns infinite (as http://regexr.com/ says).

Why? I just want to find two jointed odd numbers (two, not more) 😒.

Upvotes: 1

Views: 51

Answers (1)

Mike Christensen
Mike Christensen

Reputation: 91598

The ? character in RegEx means zero or one of the preceding set. So, your regular expression would match literally everything, as well as two odd numbers in a row.

You'll probably want something like:

[13579]{2}

Regular expression visualization

Debuggex Demo

Which means two and only two of the preceding set.

Upvotes: 1

Related Questions