Replace repeated symbol by regexprep

조회 수: 9 (최근 30일)
Sergei Zhuravlev
Sergei Zhuravlev 2017년 11월 23일
답변: Walter Roberson 2017년 11월 23일
Hello, dear Matlab experts, I'd like to change i.e. string '1,31,' to '1,31' by using regexprep. So I need to replace second, third and others commas (or to keep only the first one). There is a plenty of characters and quantifiers for using in expression but I can not find one appropriate. I.e. I use
regexprep ('1,31,',',[1]',',')
but nothing changes.

채택된 답변

Walter Roberson
Walter Roberson 2017년 11월 23일
regexprep('1,31,7,2', '(?<=,.*?),', '', 'all')

추가 답변 (1개)

Sergei Zhuravlev
Sergei Zhuravlev 2017년 11월 23일
Hope this is the answer
regexprep ('1,31,',',','',2)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by