extract word before and after character
6 次查看(过去 30 天)
显示 更早的评论
i want to extract string before "(" and after " " or "," (space comma)
example:
input: pilo(52),iko(54);
result:
pilo
iko
采纳的回答
Stephen23
2023-12-20
编辑:Stephen23
2023-12-20
C = {'input: pilo(52),iko(54)'; 'input:iko(54)'; 'input:pilo(52),iko(54)'; 'input:pilo(52),iko(54),op(23)'}
X = regexp(C,'(\w+)\((\d+)','tokens');
X = cellfun(@(c)vertcat(c{:}),X,'uni',0)
X{:}
However... regular expressions are very precise things. Writing them well requires understanding the precise conditions that they should match. Thus usually when someone posts a question with "simplified" text it just delays getting a working solution.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!