Jump to content
Sign in to follow this  
sammy1983

Unable to extract IP address

Recommended Posts

sammy1983

Hi,

Need help badly here...

I have a Word doc which has information as shown in the screenshot.

 

When I read the lines from the doc, I am receiving the entire content of the table in one line like below.

(if contractor)Static IP RangesIn House 148.186.25.1Outside Office 1Outside Office 2Contractor 1Contractor 2

No I am unable to extract just the IP address. Any help would be greatly appreciated. Thanks.

post-80752-0-74353400-1408421063_thumb.j

Edited by sammy1983

Share this post


Link to post
Share on other sites
mikell

?

#Include <Array.au3>

$str = "(if contractor)Static IP RangesIn House 148.186.25.1Outside Office 1 148.186.25.2 Outside Office 2Contractor 1Contractor 2"
$res = StringRegExp($str, '([\d.]{8,})', 3)
 _ArrayDisplay($res)

Share this post


Link to post
Share on other sites
jguinch

#Include <Array.au3>

Local $data = 'Static IP RangesIn House 148.186.25.1Outside Office 1Outside Office 2Contractor 1Contractor 2'
$aIP = _IPv4_Extract($data)

_ArrayDisplay($aIP)


Func _IPv4_Extract($sIP)
    $pattern = "(?x) (?<!\d|\d\.) ( (?:(?:  (?:(?:25[0-5]  |  2[0-4]\d  |  1\d{2}  | [1-9]\d  |  \d  )\.){3}   (?:25[0-5]  |  2[0-4]\d  |  1\d{2}  | [1-9]\d  |  \d  )  ) " & _
    " | " & _
    "(?:  (?:(?:25[0-5]  |  2[0-4]\d  |  [0-1]\d{2}  |  (00)\d  )\.){3}   (?:25[0-5]  |  2[0-4]\d  |  [0-1]\d{2}  |  (?:00)\d) )) )  (?!\d|\.\d)"

    Return StringRegExp($sIP, $pattern, 3)
EndFunc

Share this post


Link to post
Share on other sites
sammy1983

 

?

#Include <Array.au3>

$str = "(if contractor)Static IP RangesIn House 148.186.25.1Outside Office 1 148.186.25.2 Outside Office 2Contractor 1Contractor 2"
$res = StringRegExp($str, '([\d.]{8,})', 3)
 _ArrayDisplay($res)

 

Thanks a ton, Universalist.. This worked like charm.. U made my day.. Thanks again..!!!!

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  

×