• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

RegEx and PowerShell help

debian0001

Senior member
I can't for the life of me figure out the best way to regex against a text file with data I need.

I want to grab the lines that have "url": "LINK" and "name": "NAME" but I basically just want the URL itself and name so the output I want to extract is

What I want
Code:
Dribbble.com
http://dribbble.com/
Hello
http://vimeo.com/

I am messing with -match but I'm struggling :-/

Data I am working with
Code:
 "checksum": "1afdc3acef0013b8d7a187f7b5fba2ee",
      "bookmark_bar": {
         "children": [ {
            "children": [ {
               "children": [ {
                  "date_added": "12954997162224570",
                  "name": "Dribbble.com",
                  "type": "url",
                  "url": "http://dribbble.com/"
                  "date_added": "12954997162224570",
                  "name": "Hello"
                  "type": "url",
                  "url": "http://vimeo.com/"
                  "date_added": "13011572591497746",
 
crude but works according to what you desire

Code:
$data = Get-Content "info.txt"

foreach ($line in $data){
    if ($line -like "*""name"": ""*"){
        $name = $line -replace """","" -replace "name: ","" -replace ",",""
        Write-Host($name)    
    }    
    if ($line -like "*""url"":*"){
        $url = $line -replace """","" -replace "url: ",""
        Write-Host($url)    
    }
}
 
Back
Top