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

some help on Event 540

WMI Repository 4GB limit - Win 2003 Ent Question

Event ID 1302 (error 1307) DFS replication service encountered an error while writing to the debug log file