Regex Match any string powershell
$a = [regex]"\[(.*)\]"$b = $a.Match("sdfqsfsf[fghfdghdfhg]dgsdfg") $b.Captures[0].value
Match everything that isn't a bracket. Create a character class that contains anything but the bracket characters:
$line -match "\[[^\[\]]+\]"
Focusing to
"I am just trying to pick up anything that could possibly be within two brackets [ ]"
I think \[.*\]
is what you are looking for.
Explanation
Sice [
and ]
have special purposes, so you need to use \
before those characters..
(dot) stands for any character and*
stands for any number of repetition of the previous charector.
Here, the previous character is .
, so .*
stands for any general string.