regexp problem in '.'

16 ビュー (過去 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 Center および File ExchangeString Parsing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by