Thanks. That's just what I needed to know.
I'll summarize comparing Perl and PowerShell snippets. In Perl you would fill the array [ at ]cnums with all matches by
$string = "x1 c4 c1 x3 c5 c3 x2 x4 c2"; [ at ]cnums = $string =~ m/c\d/g;
The PowerShell analog would be
$string = "x1 c4 c1 x3 c5 c3 x2 x4 c2" $cnums = ([regex]::matches($string,'c\d') | %{$_.value})
"Kiron" wrote:
[Quoted Text] > I'm not sure about Perl's 'm//g' output, no Perl experience :( > To get all Regex matches in a string you can use .Net's Regex.Matches > method: > > $string = "x1 c4 c1 x3 c5 c3 x2 x4 c2" > [regex]::matches($string,'c\d') > [regex]::matches($string,'c\d') | format-table -auto > [regex]::matches($string,'c\d') | format-table Value, Index -auto > [regex]::matches($string,'c\d') | format-table value > > ...also: > > [regex]$pattern = 'c\d' > $pattern.matches($string) > $pattern.matches($string) | format-table -auto > $pattern.matches($string) | format-table Value, Index -auto > $pattern.matches($string) | format-table value > > http://msdn2.microsoft.com/en-us/library/system.text.regularexpressions.regex.matches.aspx> > -- > Kiron >
|