Jump to content
Sign in to follow this  
Anuragravi

Extract all the ip from string

Recommended Posts

Hi All

i am new to Autoit, I want to extract all ip address in array format from this string. please help 

 

#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <array.au3>

$str = "ghg shjsja 192.168.1.2 hbkjNKKSJKKN HKJCBKJLKKL 12.15.14.45 KJBKJABCKBNDKQ KHBKJABCKJQDH 1.1.1.1"

$copy = StringRegExp($str,"((\d{1,3}\.){3}\d{1,3})",$STR_REGEXPARRAYMATCH)
MsgBox(0,"",$copy[0])

Edited by Anuragravi

Share this post


Link to post
Share on other sites

Here's one of several ways to do it:

#include <Constants.au3>
#include <array.au3>

example()

Func example()
    Local $s   = "ghg shjsja 192.168.1.2 hbkjNKKSJKKN HKJCBKJLKKL 12.15.14.45 KJBKJABCKBNDKQ KHBKJABCKJQDH 1.1.1.1"
    Local $aIP = StringRegExp($s,"(?:\d{1,3}\.){3}\d{1,3}",$STR_REGEXPARRAYGLOBALMATCH)
    _ArrayDisplay($aIP)
EndFunc

 

Edited by TheXman

Share this post


Link to post
Share on other sites

also, if it's always "string space string space (target)"

#include <array.au3>

example()

Func example()
    Local $s   = "ghg shjsja 192.168.1.2 hbkjNKKSJKKN HKJCBKJLKKL 12.15.14.45 KJBKJABCKBNDKQ KHBKJABCKJQDH 1.1.1.1"
   $a = stringregexp($s , ".+?\s.+?\s(.+?)(?:\s|\z)" , 3)
   _ArrayDisplay($a)
EndFunc

 


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...