Page 1 of 1

Finding and removing brackets and the text between brackets?

Posted: Wed Feb 21, 2007 4:30 am
by mikebr
I am trying to strip text and brackets for strings, for example:

'Location name (MA)' should become 'Location name', I can't use a simple str_replace() as the chars between the brackets could be any combination of 1 to 3 letters in caps from A-Z, anyone know how I can do this easily?

Many thanks

Posted: Wed Feb 21, 2007 5:57 am
by Kieran Huggins
regular expressions seem like the best way to go

something like:

Code: Select all

preg_replace("#(\s?\([A-Z]{2,3}\))#",'');

Posted: Wed Feb 21, 2007 1:17 pm
by mikebr
I pull my hair out with these things, that did the trick and seems to work well.

Thanks