필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Help on regular expressions

조회 수: 1 (최근 30일)
Patrick Mboma
Patrick Mboma 2014년 11월 23일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi all,
I would like to extract parts of a string. In particular, I would like to extract all elements between two limits LIM> and LIM2>. For instance, if I have
LIM>ab + cd = 0LIM2>, the results should be 'ab + cd = 0'
The string is very long and there are may such instances in it. Ideally I would like to capture those parts directly as equations, but even a cell array will do.
can anyone help?
Thanks

답변 (1개)

the cyclist
the cyclist 2014년 11월 23일
s = 'LIM>ab + cd = 0LIM2> and then here it is again LIM>ef + gh = 0LIM2> and perhaps a bit more';
limIndices = regexp(s,'LIM');
numberInstances = numel(limIndices)/2;
equationCell = cell(numberInstances,1);
for ni = 1:numberInstances
startIndex = limIndices(2*ni-1) + 4;
endIndex = limIndices(2*ni) - 1;
equationCell{ni} = s(startIndex:endIndex);
end
  댓글 수: 1
Patrick Mboma
Patrick Mboma 2014년 11월 24일
I was hoping there was a straightforward regular expression to this...

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by