필터 지우기
필터 지우기

regexp problem in '.'

조회 수: 22 (최근 30일)
Yu Li
Yu Li 2019년 1월 8일
댓글: Yu Li 2019년 1월 8일
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

채택된 답변

per isakson
per isakson 2019년 1월 8일
편집: per isakson 2019년 1월 8일
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
per isakson
per isakson 2019년 1월 8일
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 2019년 1월 8일
Thank you!
Bests,
Yu

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by