Reputation: 97
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
Reputation: 1
[^(\d)]
without quantifier means that you expect exactly 1 characer that is not a number
using [^(\d)]*
will help
Upvotes: 0
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
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