Regex Get named group

25/09/2012 23:02

 

#We want to get list of IDs of controls in ascx file.
#get file
$path="c:\temp\demoForm2.ascx"
 
[regex] $regex='<asp:(textbox|label|dropdownlist)([a-zaz0-9_\ ]*)="" id="(?<idName>([a-zA-Z0-9_]*))" ' #<[:a-zAZ0-9_\ ]*((?i)TextBox|Label|DropDownList|input|select)([a-zAZ0-9_\ ]*) ((?i)ID)="(?([a-zA-Z0-9_]*))"
$a=select-string -path $path -pattern $regex -allmatches #get all matches
 
$idcka=$a|%{ $_.Matches }|%{$_.Groups['idName']}| % {$_.Value} #get all matches values in group 'idName'.
$idcka