regex - Powershell extract text from string with unknown length -
i don't think can use standard cmdlet this. have following string backup job indeterminable string here completed successfully
i need extract indeterminable string here length , number of words. text left backup job , text right either completed or failed errors.
how go this?
here go, makes use of $matches automatic variable.
$regex = "backup job (.*)(completed successfully|failed errors)" $good = "backup job indeterminable string here completed successfully" $bad = "backup job indeterminable string here failed errors" if ($good -match $regex) { $matches[1] } if ($bad -match $regex) { $matches[1] }
Comments
Post a Comment