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.

>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

Leave a Reply