简体   繁体   中英

regex ip address from string

gcc 4.6.2 c89

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

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

This is the sample string:

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

Check your OS for regex.h and use the defined regular expression library. eg linux example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM