Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何从HTML响应中grep IPv4 NSString?_Ios_Regex_Ip Address_Nsregularexpression - Fatal编程技术网

Ios 如何从HTML响应中grep IPv4 NSString?

Ios 如何从HTML响应中grep IPv4 NSString?,ios,regex,ip-address,nsregularexpression,Ios,Regex,Ip Address,Nsregularexpression,我需要获取WiFi LAN网络的公共IP地址。我正在尝试从的响应grep IP地址字符串,但失败 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!-- saved from url=(0021)http://wtfismyip.com/ --> <html><head><meta h

我需要获取WiFi LAN网络的公共IP地址。我正在尝试从的响应grep IP地址字符串,但失败

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- saved from url=(0021)http://wtfismyip.com/ -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><link rel="canonical" href="./WTF is my IP ! !  _files/WTF is my IP ! !  .html">
...
...
...
</style><script>window["_GOOG_TRANS_EXT_VER"] = "1";</script><script>window["_GOOG_TRANS_EXT_VER"] = "1";</script></head><body><div id="main"><center><p></p>  
<h2>Your fucking IP address is:</h2>  
</center><center><p>220.233.211.182</p></center>  
<center><p></p><h2>Your host name is:</h2></center>  
<center><p>182.211.233.220.static.exetel.com.au</p>  
</center><center><p></p><h2>Geographic location of your IP address:</h2></center><center><p>Sydney, 02, Australia</p></center><center><p></p>  
...  
...  
nload/download-easy.html.en">Tor Browser Bundle!</a></li></ul><p class="halb"></p></div><p></p><p></p></body></html>
匹配项为:(空)

我的代码中哪一部分出错?

请尝试此正则表达式

\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b

我能够用这个表达式解析这个页面上的ip,它仍然是(空的):(你是否正确地转义了正则表达式?要将它用作NSString,它必须看起来像这样,\\b(?:((?:25[0-5]| 2[0-4][0-9]|[01]?[0-9][0-9]\\){3}(?:25[0-5]| 2[0-4][0-9]|[01]?)\\b”。我用那个正则表达式尝试了你的代码,它成功了。只是在你的最后一行中,你必须用
[match rangeAtIndex:1]
替换
[match rangeAtIndex:0]
我确实修复了转义\。XCode注意到我了。我错过了这两个转义…非常感谢。
\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b