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
Post a Comment