Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex for characters between double quotation and end up with a comma

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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);

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading