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 to remove "(number, number)": notepad++

I’m trying to find and replace in notepad++ data from a json that has this pattern=

 "(number, number)":

I know almost nothing about regex, but I know there is a solution.

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 :

I’ll attempt to run you through the process of getting this regex.

Step 1. In order to match a single digit you need \d.

Step 2. If you need to match more than one digit, you need to to encapsulate the digit symbol into squared brackets [\d], and add a quantifier. In this specific case, the quantifier + allows to get 1 or 1+ objects belonging to the elements inside the squared brackets, hence [\d]+ will match consecutive digits, hence a number.

Step 3. In order to match two numbers separated by a comma, you just need to replicate the regex we just created and separate them by a comma and a space [\d]+, [\d]+.

Step 4. We’re almost there. We just need parentheses. You can’t just add open and closed parentheses around: you need to escape them \(, \). This formatting is necessary because parentheses are symbols that belong to the regex syntax, so escaping them (putting the \ before them) will tell tell notepad++ that those parentheses are actual parentheses (characters) instead of regex syntax.

So, the final regex is the following:

"\([\d]+, [\d]+\)"

You can try matching every step to enhance your understanding of regex.

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