Google Sheets – Using REGEXEXTRACT to Remove Characters Not Inside Brackets

formulasgoogle sheetsregexregexextract

I'm trying to create a formula that uses either =REGEXEXTRACT or =REGEXREPLACE to remove all characters not inside [brackets] but leaving the ,,, commas where they are.

For example…

➜ Text to Regex:

Checkbox 1, Checkbox 2, Checkbox 3[checked], Checkbox 4[disabled]

✔ Expected Result:

, , checked, disabled

My broken formula so far is…

=REGEXEXTRACT (J2, "\[([A-Za-z]+)\]")

✖ Current Result:

checked


Does anyone know the correct way to achieve this?


UPDATE

I created this Google Sheet to show the current work:
https://docs.google.com/spreadsheets/d/1UEO22NB9O6hvbTQzIa2YlMys1GF7ZBpe8aVzmX7dOnk/edit#gid=0

Best Answer

Try

=REGEXREPLACE(A2,"\w+\s*\d*\[?(\b\S+\b)?\]?(,?)(\s*|$)","$1$2")