extractBefore with matches string
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
eko supriyadi
el 4 de Jun. de 2022
Comentada: Voss
el 6 de Jun. de 2022
Dear all,
i'm stuck use extractBefore with this situation:
a={'32563 33308 10314 20227 30113 40117 52008 81531 333 56000 81625'}
matches333= extractBefore(a,'333')
This is because 33308 contains 333.. My goal is to retrieve the strings before pure 333 only. The result what i want is:
matches333 =
1×1 cell array
{'32563 33308 10314 20227 30113 40117 52008 81531 '}
Any idea to solve it! Tks
0 comentarios
Respuesta aceptada
Voss
el 4 de Jun. de 2022
In this case, you can include spaces around '333' to match the pure one:
a = {'32563 33308 10314 20227 30113 40117 52008 81531 333 56000 81625'}
matches333 = extractBefore(a,' 333 ')
But that won't work if '333' is at the end:
a = {'32563 33308 10314 20227 30113 40117 52008 81531 333'}
matches333 = extractBefore(a,' 333 ')
10 comentarios
Voss
el 6 de Jun. de 2022
If you want to take the remainder of each char array after '333' (where '333' is its own "word"), I would use the same regular expression as before, and adjust the indexing:
a = {'32563 33308 10314 20227 30113 40117 52008 81531 333 56000 81625','32563 33308 10314 20227 30113 40117 52008 81531 333'};
after333 = repmat({''},length(a),1);
idx = regexp(a,'\<333\>','once');
for ii = 1:numel(a)
if ~isempty(idx{ii})
after333{ii} = a{ii}(idx{ii}+4:end);
end
end
disp(after333);
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!