I am wanting to grep for 192.168.22.xxx and 192.168.23.xxx. with a single grep statement where xxx can be any number.

I have tried

grep -Eo '192.168.2[2][3]\.[0-9]{1,3}'


grep -Eo '173.235.2[2][3][\.][0-9]{1,3}'

But this does not return anything. What is the correct regex I need to be using?


Instead of [2][3] use [23]. Options should be included in the same [] group.

Also escape . every time:
grep -Eo '192\.168\.2[23]\.[0-9]{1,3}'

You can test it here

  • Ah! I was close lol. – user53029 Aug 23 '16 at 6:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.