Given the following key value pairs, how could I match just the values (including the quotes)?
Explanation: I'm doing a find and replace in my IDE. I have hundreds of key/value pairs where the values need to be changed from strings to objects. So basically replacing the value.
"ElevationFilenameIn": "Input raster elevation file",
"TargetCRS": "Target vertical coordinate reference system Type",
"featureName": "The name of the feature to extract, for example \"Vegetation\" or \"Water\"",
"TargetCRScode": "Target vertical coordinate system Code",
"TargetCRSfile": "The projection (.prj) file in shoebox to be used for this inputfile"
My attempt (which is not working, not even close):
[:]\s*(\"\w*\")
A JSON object contains zero, one, or more key-value pairs, also called properties. The object is surrounded by curly braces {} . Every key-value pair is separated by a comma.
JSON strings can't have functions or regex literals.
JSON Data - A Name and a ValueJSON data is written as name/value pairs (aka key/value pairs).
You can use the pattern:
[:]\s(\".*\")
and test it following this link: https://regex101.com/r/nE5eV3/1
I guess this one does the job also well. One good part it doesn't use any capture groups one bad part it's more costly compared to the accepted answer.
[^:]+(?=,|$)
Debuggex Demo
Regex101 Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With