Roy Tang

Programmer, engineer, scientist, critic, gamer, dreamer, and kid-at-heart.

Blog Notes Photos Links Archives About

need a regular expression for “an alphanumeric string inside hard brackets”

Posted by under notes at
Also on: twitter facebook / 6

Comments

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!