MATLAB: Extracting second number after comma within parenthesis

MATLABregexpstrings

I have a string
"Toc(Clock Data Ref Time) : 0x91E6 (37350,5.976000e+005 s)";
I am looking to extract only contents after comma from the second parenthesis.
So, the required would be 5.976000e+005.
My code is
XX="Toc(Clock Data Ref Time) : 0x91E6 (37350,5.976000e+005 s)";
TOC=strrep(XX,'Toc(Clock Data Ref Time)','');
TOC=regexp(TOC, '(?<=\()[^)]*(?=\))', 'match')
Which returns 37350,5.976000e+005 s.
But how to extract numbers after comma?
Thank you.

Best Answer

Assuming that the number will always be in scientific notation, then the following should work.
TOC = regexp(str,'(?<=\(.*?,)\d\.\d+e\+\d+(?=.*?\))','match');
% A rough description of what pattern the expression is indicating
% (?<=\(.*?,) Look behind an open parenthesis for an optional set of any characters until reaching the following pattern
% \d\.\d+e\+\d+ A single digit followed by a period, followed by 1 or more consecutive digits, followed by e+,
% followed by 1 or more consecutive digits.
% This pattern this must precede the following look-ahead assertion.
% (?=.*?\)) Any optional set of characters before a closed parenthesis.