I am having some trouble writing a regex expression that will strip outer brackets from a string (I want to ensure any brackets within single/double quotes are preserved):
((0)) becomes 0
(0) becomes 0
('(0845) 187 1262') becomes '(0845) 187 1262'
I have got two regexes to match the left and right hand outer brackets:
^[\(]* -- matches out the left outer brackets
[\)]*$ -- matches out the right outer brackets
Is it possible to combine both into a single regex?
Yes, it’s not at all difficult, and your regex can be simplified as well, as you don’t need character classes: