Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Help on regular expressions

1 visualizzazione (ultimi 30 giorni)
Patrick Mboma
Patrick Mboma il 23 Nov 2014
Chiuso: MATLAB Answer Bot il 20 Ago 2021
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

Risposte (1)

the cyclist
the cyclist il 23 Nov 2014
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 Commento
Patrick Mboma
Patrick Mboma il 24 Nov 2014
I was hoping there was a straightforward regular expression to this...

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by