Hello All
Recently I posted a quick example of "Checking how may times a substring appears in a string" using RegEx and the experts on the forum kindly following up with some examples using select-string.
Here is another RegEx example that may help people out when trying to capture several elements of a string into different groups, then displaying (or storing in a variable) the results of all total captures per group.
cls
$matches=$null
$Subject="Hello my name is Ernest Brant"
$Pattern="\w{5}.(?<Content>..).(?<Another>....)(?<Content>...).(?<Another>.+)"
"Content captured. $(([regex]::Match($Subject,$Pattern)).Groups['Content'].captures | % {$_.value})"
"Another captured. $(([regex]::Match($Subject,$Pattern)).Groups['Another'].captures | % {$_.value})"
the output from the above is
Content captured. my is
Another captured. name Ernest Brant
This is a very basic example, but the technique can be useful to others
Ernie