필터 지우기
필터 지우기

find/remove 2 consecutive letters from string

조회 수: 6 (최근 30일)
Zoe Zhang
Zoe Zhang 2012년 1월 3일
Tried the regexp(regexprep) family, still don't know how to get this to work...
I have a cell array of strings, some of which looks like: '.XNY.N'
I simply need to check the cell array, if there is a .N or .M, remove it. Same as in excel you select an array and replace .N and .M with empty.
So in this case '.XNY.N' will be '.XNY'
Anyone knows how to do that? Thanks in advance!

채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 1월 3일
regexprep('.XNY.N','[.]N','')
  댓글 수: 2
Zoe Zhang
Zoe Zhang 2012년 1월 3일
I see, so [] means the consecutive letter. Thank you!
Walter Roberson
Walter Roberson 2012년 1월 3일
Andrei's answer involved [.] with a period between the brackets. That is one of the ways in which you can code a literal period. Normally in regular expressions, a period is interpreted to mean "any character". You can also use \. to indicate a literal period.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 1월 3일
Slightly closer to your original question, and using a different regexp pattern:
regexprep('.XNY.N','\.[MN]','')

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by