Reputation: 4076
$lines = '<string>D:\home\bob\utility.mdb</string>'
[String[]]$varr = $lines | Select-String -AllMatches -Pattern "<string>*.mdb" |
Select-Object -ExpandProperty Matches |
Select-Object -ExpandProperty Value
This is returning null.
Ultimately I want the entire line, from the <string>
to the </string>
.
But apparently I don't know how to express this in powershell.
Upvotes: 0
Views: 74
Reputation: 71538
In your initial example:
<string>[\s]*.mdb[\s]*
the first [\s]* will not match anything. You perhaps intended:
<string>[\S]*.mdb[\s]*
But then, I think that the property Matches
will take in the whole string from start to end, meaning you'll have to put everything, and the dot needs to be escaped since you can call it a wildcard:
<string>[\S]*\.mdb[\s]*<\/string>
And I think you can remove some unneeded parts (I'm not too familiar with powershell's regex, but I haven't seen any where you have to put character classes written like \S
within square brackets):
<string>\S*\.mdb<\/string>
Little explanation:
\s
matches a space character, and often also matches a newline, or a tab (\n
and \t
respectively).
\S
will match everything that \s
doesn't match.
Upvotes: 1