的另一种方法:
regexpi(output(~isspace(output)), found, 'match')
如果output
是一个字符串,或
regexpi(regexprep(output,'\s',''), found, 'match')
用于更一般的情况(class(output) == 'cell'
或'char'
)。
优点:
- 快。
- 健壮(所有空格(不只是空格)被删除)
- 更灵活(您可以返回匹配,标记等的开始/结束索引。)
- 将在输出返回匹配的原始情况下
缺点:
- 更打字
- 不太明显(需要更多的文档)
- 将返回匹配的原始情况下输出(是的,这个硬币有两面)
那在两份名单的最后一点是很容易被迫降低或使用lower()
或upper()
大写,但如果你想同样的情况,这是一个有点更复杂:
C = regexpi(output(~isspace(output)), found, 'match');
if ~isempty(C)
C = found; end
单串,或
C = regexpi(regexprep(output, '\s', ''), found, 'match')
C(~cellfun('isempty', C)) = {found}
对于更一般的情况。
我必须在输出日志上做到这一点 – lola
found ='thetest:passed'然后当我在输出中搜索时,我还需要忽略输出中的空格... – lola
@lola然后还使用'output = lower(output(output〜=''))' –