MATLAB: Extract the number within the bracket

number within the bracket

I have string a = 'a_b_c_d(1.0)'
I need to extract the number within the bracket.
my answer shoud be b = '1.0'
how can i do this using regular expression or other method?
Thank you

Best Answer

Any number of regular expression would do 'extract whatever is between two brackets:
str = 'a_b_c_d(1.0)';
regexp(str, '(?<=\()[^)]*(?=\))', 'match', 'once')
is one possibility. This
  • looks ahead for an opening bracket.
  • matches any number of characters as long as they're not a closing bracket
  • looks behind for a closing bracket.