I have a language json file like this:
"FAQs": "FAQs",
"Contact": "Contact",
"Log in": "Log in",
I want to translate the second values
How do I select all second values that is between double quotation and end up with a comma with regex?
>Solution :
In these posts, please also show what you have already tried. This seems something you could have easily googled.
Here is Regex solution. But I recommend using features of whatever language you are using to read JSON file.
To select all second values in your JSON file that are between double quotation marks and end with a comma using regex, you can use a regular expression that targets exactly this pattern. Here’s a regex pattern that should work for your requirement.
"([^"]+)",
Let’s break it down:
- ": Matches the opening double quotation mark.
- ([^"]+): This is a capturing group that matches any sequence of
characters that are not a double quotation mark - ([^"]). The + means
it will match one or more of these characters. - ": Matches the closing
double quotation mark. - ,: Matches the comma following the closing
quotation mark.
let jsonString = { "FAQs": "FAQs", "Contact": "Contact", "Log in": "Log in" };
let matches = jsonString.match(/"([^"]+)",/g);
console.log(matches);