Rubber
Rubber

Reputation: 117

How to select range 160 to 255 in regex

I have tried this way to find the result, But it's also select 10 to 19.

([1][6-9]?[0-9])|([2][0-4][0-9])|(25[0-5])

So please help how to select without 10 to 19.

Upvotes: 0

Views: 155

Answers (2)

Mark Homans
Mark Homans

Reputation: 757

here is an answer with less parentheses and brackets: 1[6-9][0-9]|2([0-4][0-9]|5[0-5])

Upvotes: 1

Tushar
Tushar

Reputation: 87203

Remove the ? from [6-9] in the first group. ? quantifier will make the character class [6-9] appear zero or once.

The question mark makes the preceding token in the regular expression optional.

([1][6-9][0-9])|([2][0-4][0-9])|(25[0-5])

You can also group them together as

([1][6-9][0-9]|[2][0-4][0-9]|25[0-5])

Upvotes: 2

Related Questions