combine two regexprep into one

Hi, I was wondering if I can reduce the two lines of code into one? Thank you
selected = regexprep(selected, ' ',' ');
selected = regexprep(selected, '<.*?>','');

 采纳的回答

I have no idea what you are trying to do. My regex foo is weak, but I am pretty sure for your example you can just replace both lines with
selected = selected;
For a more general one line solution you could do
selected = regexprep(regexprep(selected, ' ',' '), '<.*?>','');
Are you trying to find a single regex expression that does the (non) replacement?

2 个评论

duh... yeah that works thank you
It may work, but I wouldn't do it. The way you have it is so much more readable and maintainable.

请先登录,再进行评论。

更多回答(1 个)

Sean de Wolski
Sean de Wolski 2013-6-3

1 个投票

Why bother?
That works and is likely easier to understand!

类别

在 帮助中心 和 File Exchange 中查找有关 Characters and Strings 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by