not for a string in regular expressions

조회 수: 15 (최근 30일)
Hadas Lewinsky
Hadas Lewinsky 2018년 2월 8일
편집: per isakson 2018년 4월 22일
How do I search a sequence for a certain match not containing a certain substring?
As in wanting to search an RNA sequence starting with CG and not containing AG in the middle and then ending with it? When I run
regexp(mRNA, 'GU\w+[^AG]AG');
it gives me the location of matches that dont contain either A or G in the middle, and not the 'AG' substring.
Would really appreciate the help!

답변 (1개)

Walter Roberson
Walter Roberson 2018년 2월 8일
Presuming that mRNA is a cell array of character vectors, then
mask = ~cellfun(@isempty, regexp(mRNA, '^CG([^A]|A[^G])*AG$', 'lineanchors', 'once'));
matched_strings = mRNA(mask);

카테고리

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