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 find space, square bracket, any number, closing square bracket and comma e.g., ( [number],)

I am new to Regex and I need help in creating a Regex that is able to find space, open square brackets, any number, close square brackets and commas in a text. For example:

Text File:

{
"text": [
      {
        "text": "textg [65]",
        "text": "text text text [65], text [65], text [65], text [65]"
      },
      {
        "text": "text text [77]",
        "text": "textpoint text [77], textgrade [77], text [77], text [77]"
      }
    ]
  }

I want only (space)[65], and (space)[77], as output.

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 :

You can use the following regex:

\s\[\d+\],

in total 6 matches are found from the example you provided:

 [65],
 [65],
 [65],
 [77],
 [77],
 [77],

regex101 link

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