简体   繁体   中英

RegEx to find value in JSON

I need to write a RegEx on a JSON to match everything that starts with {$ and ends with }

I tried with /{(.*?)}/g and it seemingly works fine but if you see the image below it also matches the other text so how do I explicitly write a RegEx for my requirement

The reason for the ask is I need to find values with {$*} and replace them with a string

在此处输入图像描述

Below is my JSON

{
    "name": "{$StubName}",
    "request": {
        "method": "POST",
        "url": "/marks/{$Name}",
        "bodyPatterns": [
            {
                "equalToJson": "{\n    \"name\": \"{$RequestName}\",\n    \"job\": \"{$Role}\"\n}"
            }
        ]
    },
    "response": {
        "status": "201",
        "headers": {
            "Content-Type": "application/json"
        },
        "body": "{\n    \"name\": \"{$RequestName}\",\n    \"job\": \"{$Role}\",\n    \"id\": \"{$id}\",\n    \"createdAt\": \"{$Time}\"\n}"
    }
}

You can use \{\$\w*\}

Regex demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM