两个IP地址匹配

时间:2012-06-25 10:00:09

标签: sql regex ip-address

我需要将两个ipaddress与正则表达式匹配: 像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]

目前我正在使用类似这样的正则表达式:".*[^(\d)]20.20.20.20[^(\d)].*" 但它不适用于第一和第三种情况。请帮助我使用这个正则表达式。

3 个答案:

答案 0 :(得分:2)

你忽略了该行以20.20.20.20开头的情况:

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

似乎对我有用

答案 1 :(得分:0)

你可以这样做:

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

答案 2 :(得分:0)

没有量词的

[^(\d)]意味着你只期望1个不是数字的字符 使用[^(\d)]*将有助于

相关问题