字符串中的正则表达式 ip 地址 [英] regex ip address from string

查看:46
本文介绍了字符串中的正则表达式 ip 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

gcc 4.6.2 c89

gcc 4.6.2 c89

是否有任何标准的正则表达式可用于从字符串中提取 IP 地址.

Is there any standard regex expression that can be used to extract the IP address from a string.

我正在考虑使用带有正则表达式的 sscanf 来从下面的示例字符串中获取 IP.

I am thinking about using sscanf with a regex expression to get the IP from this sample string below.

这是示例字符串:

v=0 o=sip_user IN 10230 22472 IP4 NET.CAT.NTBC s=SIP_CALL c=IN IP4 10.10.10.44 m=audio 49152 RTP/AVP 0 a=rtpmap:0 PCMU/8000

所以正则表达式将在引号之间:

So the regex will be in between the quotes:

sscanf(ip_string, "%s", &ip_address);

非常感谢您的任何建议,

Many thanks for any suggestions,

推荐答案

\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 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆