Extract IP address

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

Moderator: Rathinagiri

Post Reply
User avatar
bpd2000
Posts: 1020
Joined: Sat Sep 10, 2011 4:07 am
Location: India
Has thanked: 165 times
Been thanked: 72 times

Extract IP address

Post by bpd2000 » Sun Aug 20, 2017 12:05 pm

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: 239
Joined: Tue Aug 13, 2013 4:46 am
Location: Indonesia
Has thanked: 1 time
Been thanked: 4 times

Post by hmgchang » Wed May 09, 2018 11:29 pm

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