MATLAB: Removing parentheses around digits using regular expressions

expression parsingregular expressionstring

Dear all, I am slowly making progress on my learning of regular expressions. At the moment, I am trying to solve the following problem: replace all occurrences of (n) with n, where n is a number, provided that no alphabetical letter occurs before the first parenthesis. As an example,
str='(2)+p_5*(3)-(0.3)'
would become
2+p_5*3-0.3
I wrote the following
regexprep(str,'(\W)(\()([.012345789]+)(\))','$1$3')
but it does not solves the problem if one of the expressions to change occurs at the beginning as in the example above. More concretely, the answer I get from running this is
(2)+p_5*3-0.3
which is not the expected result.
Thanks in advance for any help
Pat.

Best Answer

regexprep(str,'(\()([\d*\.]+)(\))','$2')