need a regular expression for “an alphanumeric string inside hard brackets”
Bracketted statement?
Bry's reply on twitter is sound. "[[a-zA-Z0-9]* ]" As long as there is no leading unescaped opening bracket ("[") you can escape a closing bracket ("]").
Panu kung "[]"? Ok lang ba na empty?
I'm already doing something similar (python): >>> p = re.compile('[[ A-Za-z0-9\s]]*\ ]') >>> p.sub('', '4 [remove this] blahblah') '4 [remove this] blahblah' what am I doing wrong?
You could try the \w character class instead of the [a-zA-Z0-9] but it would include the underscore character
Got it! I had typed an extra ] into the regex: >>> p = re.compile('[[ A-Za-z0-9]*]') >>> p.sub('', '4 [removethis] blahblah') '4 blahblah' Thanks internet!
If you enjoyed my content for some reason, I'd love to hear from you! Here are some options:
- You can buy me a coffee!
- You can share or reply to this post on Twitter.
- You can write a reply on your own site and submit the URL as a webmention via the form below.
- Or you can just contact me!