user1479571
user1479571

Reputation: 97

Two IP Address match

I need to match two ipaddress with a regular expression: Like 20.20.20.20

should match with      20.20.20.20
should match with      [http://20.20.20.20/abcd]
should not match with  20.20.20.200
should not match with  [http://20.20.20.200/abcd]
should not match with  [http://120.20.20.20/abcd]

At present i am using something like this regular expression: ".*[^(\d)]20.20.20.20[^(\d)].*" But it is not working for the 1st and 3rd case.Please help me with this regular expression.

Upvotes: 1

Views: 186

Answers (3)

xarfai
xarfai

Reputation: 1

[^(\d)] without quantifier means that you expect exactly 1 characer that is not a number using [^(\d)]* will help

Upvotes: 0

shashwat
shashwat

Reputation: 1002

You're ignoring the case where the line starts with 20.20.20.20:

"(.*[^(\d)]|^)20.20.20.20([^(\d)].*|$)"

seems to work for me

Upvotes: 2

aF.
aF.

Reputation: 66737

You can do it like this:

select * from tablename
where ip = '20.20.20.20' or ip like 'http://20.20.20.20/%'

Upvotes: 0

Related Questions