如何用Regex仅捕获CLUTCH_BOONS内的+并修复JSON语法问题
Fixing Your Malformed JSON with Regex (Atom/Regexr)
Let's break this down into two straightforward fixes to get your JSON into the desired format.
1. Fix the BOONS Array Syntax & Split the Combined Value
Your BOONS entry is missing the closing bracket ] and needs the + replaced with a comma to split the two values. Here's how to fix it:
- Open the find-and-replace panel (Atom:
Cmd/Ctrl + F, then enable regex mode with the.*icon) - In the find field, paste this regex:
"BOONS": \["([A-Za-z]+)\+([A-Za-z]+)" - In the replace field, paste:
"BOONS": ["$1","$2"] - Run the replacement. This will:
- Capture the two values separated by
+(DebarrierandRainbow Shift) - Replace the
+with","to split them into separate array elements - Add the missing closing bracket
]to fix the array syntax
- Capture the two values separated by
2. Only Replace + Inside CLUTCH_BOONS Array
To target only the + within the CLUTCH_BOONS array (and leave other +s untouched), use this lookaround-based regex:
- In the find field, paste:
(?<="CLUTCH_BOONS": \[.*?)(\+)(?=[^\]]*?\]) - Replace matches with:
"," - The lookaround assertions ensure we only match
+characters that are:- After the
CLUTCH_BOONS: [` opening - Before the corresponding
]closing the array
- After the
Final Result
After both steps, your JSON will be corrected to:
"BOONS": ["Debarrier","Rainbow Shift"] }, "CLUTCH_BOONS": [ "Boost","Wall" ],
内容的提问来源于stack exchange,提问作者Ginzo Milani
相关产品推荐
相关产品推荐

