Regular Expressions

Okay you have a text file or log file that contains a lot of data e.g. you have the source code of a website with a lot of usefull links. Let's say you want to extract only all the links.

$var=get-content .\websitesourcefile.txt
$regex=[regex]"www.\w+\.\w+"
foreach ($m in $regex.matches($var)) {$m.value}

This will show you all the entries starting with www.something.something
This will not however get the sites that don't start with www. So let's get those too:
$var=get-content .\websitesourcefile.txt
$regex=[regex]"http\:\//\w+\.\w+\.\w{1,7}"
foreach ($m in $regex.matches($var)) {$m.value}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License