Page 1 of 1

Extract IP address

Posted: Sun Aug 20, 2017 12:05 pm
by bpd2000
Extract first single IP address from text/string
Contact me for multiple IP extract

Code: Select all

// extract first single IP address from text
// bpd2000

Function Main
      LOCAL cRegEx :="[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"
      LOCAL cText  := "Kindly note my IP Address: 192.168.1.1 "
      LOCAL nStart, nLen
         
      LOCAL cIP := HB_AtX( cRegEx, cText, .F., @nStart, @nLen ) 
      
      MSGINFO( cText,"Sample String" )
      MSGINFO( cIP, "Extracted IP is" + space(10) )
 
 RETURN

Re: Extract IP address

Posted: Wed May 09, 2018 11:29 pm
by hmgchang
maybe this may help,

Code: Select all

// extract first single IP address from text
// bpd2000

Function Main
      LOCAL cRegEx :="[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"
      LOCAL cText  := "Kindly note my IP Address: 192.168.1.1 "
      LOCAL nStart, nLen
      LOCAL cIP
      
      cText += HB_EOL() + "other IP is : 192.169.1.100"
      aIp := hb_regexAll( cRegEx, cText)   
      
      msgDebug( aIp)
      
      cIP := HB_AtX( cRegEx, cText, .F., @nStart, @nLen ) 
      
      MSGINFO( cText,"Sample String" )
      MSGINFO( cIP, "Extracted IP is" + space(10) )
 
 RETURN
[/code/