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

ferada
11.4k25 silver badges65 bronze badges
asked May 26, 2016 at 6:26
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

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

answered May 26, 2016 at 6:52
\$\endgroup\$
2
  • \$\begingroup\$ that was actually my first attempt but i don't know why i made it complex BTW thanks \$\endgroup\$ Commented May 26, 2016 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\$ Commented May 26, 2016 at 7:45

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.