2012-06-25 88 views
1

我需要用正则表达式匹配两个ip地址: 像20.20.20.20两个IP地址匹配

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)].*" 但它无法正常工作为第一和第三个case.Please帮助我这个正则表达式。

回答

2

你忽略的情况下,一些 其中行开头20.20.20.20:

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

似乎为我

0123工作
+0

感谢您的解决方案:) – user1479571

0

你可以这样说:

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

你的解决方案是好的,但看看标签,我认为他想要一个正则表达式。 –

+1

@cad有可能,让我们看看OP说的是什么。 –

+0

你是对的,也许他可以将逻辑移动到查询:) –

0

[^(\d)]没有量词意味着你能确切1个characer不是使用[^(\d)]*将有助于

+0

感谢您发现正则表达式的问题。它正在努力:) – user1479571