cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

This product reached the end of support date on March 31, 2021.

How to generate a Regex for multiple IP Address ??

laxmi_prakash
Newcomer

Dear All,

I want to generate a Regex expression for multiple IP addresses, but there's a twist i want expression like suppose I have URL: www.google.com --< URL has been accessed by different client IP.

So i need client IP - (xxx.xxx.247.* or xxx.xxx.245.*) that Hits the Url (www.google.com) out of (xxx.xxx.247.*,xxx.xxx.245.*)

Its like Logical Or operation i need to do ??

2 REPLIES 2

Steven_Monroe
Inactive

Hi Laxmi,

Probably the simplest way to handle 'OR' as you are asking is to use a character set.

The RegEx 24[57] will match an input of 245 or 247. The [57] is a character set and will match on an input that has a 5 or a 7 at the specified position. So 24[517] would match 245, 241, or 247.

Here is a RegEx you could use to match any IP with 245 or 247 as the third octet:

\d{1,3}\.\d{1,3}\.24[57]\.\d{1,3}

This technically matches on invalid IPs as well such as 999.999.245.999 so if you don't like that you can use a more specific and complicated RegEx like:

(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.24[57]\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])

But really you should be fine with the simpler RegEx if you're not expecting or concerned about invalid IPs. Let me know if that RegEx works for your scenario.

Regards,
Steve

laxmi_prakash
Newcomer

Hi Steve,

Thank you, with your provided explanation i am good to resolve the transformation regex as per my requirement.

with regards,

Laxmi Prakash