Regex PowerShell


hi,

i have following need : in web page source (or text file) , want find content between 2 values, iterate on results.

the syntax of text file following :

"tag1":"http://commoncompanyurl.company.com/lists/valueiwanttoretrieve","tag2"

thanks.


my technical blog on sharepoint || contributions on technet gallery

the regular expression depend on how of data static.  if treat in bold variable, , else static (plus allowing whitespace around comma and/or colon), this:

$string = @'     "tag1" : "http://commoncompanyurl.company.com/lists/valueiwanttoretrieve" , "tag2"     "tag1" : "http://commoncompanyurl.company.com/lists/someothervalueiwanttoretrieve" , "tag2" '@  $pattern = '"tag1"\s*:\s*"http://commoncompanyurl\.company\.com/lists/([^"]+)"\s*,\s*"tag2"'  select-string -inputobject $string -pattern $pattern -allmatches | select-object -expandproperty matches | foreach-object {     $_.groups[1].value }



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

directory stack

After enabling Windows Server 2012 R2 DHCP Failover Getting Packet dropped because of Client ID hash mismatch

WMI Repository 4GB limit - Win 2003 Ent Question