Extract IP address

Other General Resources like icon sets, sound files etc.,

Moderator: Rathinagiri

Post Reply
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Extract IP address

Post 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
BPD
Convert Dream into Reality through HMG
User avatar
hmgchang
Posts: 273
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia

Re: Extract IP address

Post 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/
Just Hmg It !
Post Reply