Powershell - Pulling a substring from a uri -


i'm trying pull this

hrbkr.com smqzc.com znynf.com 

from list of uri's in $temp -

anything.anything.hrbkr.com anything.anything.smqzc.com anything.anything.znynf.com 

this regex seems match @ least on regex101 -

(<domainname>(?<ip>^[a-fa-f\d.:]+$)|(?<nodots>^[^.]+$)|(?<fqdomain>(?:(?:[^.]+.)?(?<tld>(?:[^.\s]{2})(?:(?:.[^\.\s][^\.\s])|(?:[^.\s]+)))))$)*?' 

but doesn't seem give me results, able match whole line, want 'substring' not true if line matches.

$temp = ‘c:\users\money\downloads\phishinglist.txt’ $regex = '(<domainname>(?<ip>^[a-fa-f\d.:]+$)|(?<nodots>^[^.]+$)|(?   <fqdomain>(?:(?:[^.]+.)?(?<tld>(?:[^.\s]{2})(?:(?:.[^\.\s][^\.\s])|(?:[^.\s]+)))))$)*?' $temp | select-string -pattern $regex -allmatches | % { $_.matches } | % { $_.value } | sort-object -unique > $list $list 

thanks!

if file contains fqdns , nothing else, can solve simple -split , -join operation:

# split fqdn individual labels $labels = 'anything.anything.smqzc.com' -split '\.'  # grab second-to-last , last label, join dot $domain = $labels[-2,-1] -join '.' 

or in single statement:

$domain = ("anything.anything.smqzc.com" -split '\.')[-2,-1] -join '.' 

so procedure ends looking like:

$list = get-content $home\downloads\phishinglist.txt |foreach-object {     ($_ -split '\.')[-2,-1] -join '.' } 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -