Extract the 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
4 件のコメント
Brian Hannan
2015 年 6 月 29 日
How about this?
regexp(x,'(?<=\().*(?=\))','match')
Gopalakrishnan venkatesan
2015 年 6 月 29 日
Guillaume
2015 年 6 月 29 日
It may be safer to use a non-greedy * (that is *?) in case there is more than one bracketed expression in the string.
Brian Hannan
2015 年 6 月 29 日
Good idea.
採用された回答
その他の回答 (1 件)
This extracts all digits and all '.' from a:
numstr = a(regexp(a, '[\d\.]'))
This extracts all numbers between ( ), where number must have at least one digit before the point and one digit after the point:
numstr = regexp(a, '\((\d+\.\d+)\)', 'tokens')
The outer \( and \) match the '(' and ')', resp., in a, and the inner ( ) are meta-characters to group a token.
カテゴリ
ヘルプ センター および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!