Separating numbers and characters from input
Show older comments
If a user inputs a random amount of characters For example: str=input(prompt,'s'); and they input: 123wd57ab934bd3 how can I separate the numbers and the characters? Thank you!
Answers (1)
Andrei Bobrov
on 25 Oct 2016
str = '123wd57ab934bd3';
z = regexp(str,'(\d*)([a-z]*)','tokens');
out = [z{:}];
out = out(~cellfun(@isempty,out));
3 Comments
Thorsten
on 25 Oct 2016
If you want them separately
numbers = regexp(str,'(\d+)','match');
chars = regexp(str,'([a-z]+)','match');
Valeria Chacon
on 25 Oct 2016
Andrei Bobrov
on 26 Oct 2016
str = '123wd57ab934bd3';
z = str2double(regexp(str,'\d*','match'));
Categories
Find more on Variables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!