Extract Variables from mixed string
1 次查看(过去 30 天)
显示 更早的评论
Hi all,
In this string
'# Message: onset_pic1_8.png'
how can I read 'onset', 'pic', '1', '8' in four variables?
采纳的回答
Walter Roberson
2018-8-12
S = '# Message: onset_pic1_8.png';
parts = regexp(S, '(?<name1>[A-Za-z]+)_(?<name2>[A-Za-z]+)(?<num1>\d+)_(?<num2>\d+)', 'names')
parts =
struct with fields:
name1: 'onset'
name2: 'pic'
num1: '1'
num2: '8'
I coded to permit uppercase as well as lowercase, but I did assume that the alphabetic parts remain alphabetic and the numeric parts remain numeric.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!