I have a string and I want to split it with '.', but the regexp does not work.
test='abcde.abcde';
regexp(test,'.','split')
but it does not work, the result is a 1*12 cell array.
however, if I replace the '.' with other symbol, such as '_', the regexp function works properly.
test='abcde_abcde';
regexp(test,'_','split')
just want know if there is any mistake with my operation? or, is this a feature in 'regexp' function?
Thanks!
Yu

 Respuesta aceptada

per isakson
per isakson el 8 de En. de 2019
Editada: per isakson el 8 de En. de 2019

0 votos

Try
%%
test='abcde.abcde';
regexp(test,'\.','split')
returns
ans =
1×2 cell array
{'abcde'} {'abcde'}
dot stands for any single character. An escape is needed to a literal dot.

3 comentarios

Yu Li
Yu Li el 8 de En. de 2019
Thank for your answer, the problem has been solved.
could you please explain why this happens and why your answer works?
Thanks!
Yu
per isakson
per isakson el 8 de En. de 2019
dot is a Metacharacters, see the documentaion, which says:
. Any single character, including white space, '..ain' matches sequences of five consecutive characters that end with 'ain'.
Yu Li
Yu Li el 8 de En. de 2019
Thank you!
Bests,
Yu

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Preguntada:

el 8 de En. de 2019

Comentada:

el 8 de En. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by