powershell - Regex to extract an IP address from a string -


this question has answer here:

i'm trying retrieve ip address string. i'm not first ask question, couldn't find answer doing need.

if there somewhere in string combination of xxx.xxx.xxx.xxx, regardless of text around it, should extract number dots in between. can used test-connection.

i'm not trying determin if ip address valid, trying retrieve ip address string. if invalid, 900.999.800.254.

example:

input             expected result -----             --------------- ip_10.57.50.91    10.57.50.91 10.57.50.73       10.57.50.73 10.58.4.37 ip     10.58.4.37 ip 10.63.1.22     10.63.1.22 belprlixh300      $false ip 10.63          $false 

i've tried far the regex's suggested here don't give ip address output in variable $matches.

$ips = @('ip_10.57.50.91',     '10.57.50.73',     '10.58.4.37 ip',     'ip 10.63.1.22',     'belprlixh300',     'ip 10.63' )  $regex = [regex] "\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"  $regex.matches($ips) | %{ $_.value } 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -