Difference between revisions of "Power Shell"
Jump to navigation
Jump to search
(→Exceptions and Error Handling: Added "Try...Catch") |
(→Strings: Added "Match (extract)") |
||
Line 111: | Line 111: | ||
{ | { | ||
# StringToFind found in $text | # StringToFind found in $text | ||
} | |||
</source> | |||
<br>'''Match (extract)'''<br> | |||
To extract text that matches a regex... | |||
<source lang="powershell"> | |||
$res = [regex]::matches($line, "\d{4}-[A-Za-z]{3}-Week\d{1}.log") | |||
if (-not $res.Count) | |||
{ | |||
# No matches found | |||
} else { | |||
$res1 = $res.Item(1).Value # 1st match to regex | |||
} | } | ||
</source> | </source> |