0
\$\begingroup\$

I need to remove all the numbers appearing inside square braces such as [9] , [2] , ....

This is my regex:

"(?:\[\d*\])"

Which is working fine. But I am totally new to regex so let me know if is there a better regex that can be used.

Try Online

\$\endgroup\$
1
\$\begingroup\$

You don't need the grouping here, and also you'd want to match for 1 or more digits: "\[\d+\]"

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ that was actually my first attempt but i don't know why i made it complex BTW thanks \$\endgroup\$ – mak May 26 '16 at 7:09
  • \$\begingroup\$ The problems with regexen is that they're easier to write than to read. Which means that for simple regexen it might be a good idea to start over instead of tweaking an existing solution. \$\endgroup\$ – Anselm Helbig May 26 '16 at 7:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.