如何在MATLAB中将字符串解析为字母,数字等? [英] How can I parse a string into letters, digits, etc., in MATLAB?

查看:842
本文介绍了如何在MATLAB中将字符串解析为字母,数字等?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MATLAB中,我有一串这样的字符'12hjb42&34ni3&(*&'.

I have a string of characters like this '12hjb42&34ni3&(*&' in MATLAB.

我想通过正则表达式或其他更简单的方法来分隔数字和字母以及其他所有内容.我该怎么办?

I want to separate the digits and letters and everything else through regex or some other easier way. How can I do this?

推荐答案

我认为使用函数哪个会给您这些结果:

alphaStr = 'hjbni'
digitStr = '1242343'
otherStr = '&&(*&'

如果您真的想使用 REGEXP ,这是您的操作方式:

If you really wanted to use REGEXP, this is how you could do it:

matches = regexp(str,{'[a-zA-Z]','\d','[^a-zA-Z\d]'},'match');
alphaStr = [matches{1}{:}];
digitStr = [matches{2}{:}];
otherStr = [matches{3}{:}];

这篇关于如何在MATLAB中将字符串解析为字母,数字等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆