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 Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by