フィルターのクリア

regexp function - get index of string with two conditions

2 ビュー (過去 30 日間)
Lorenz
Lorenz 2022 年 7 月 25 日
コメント済み: Lorenz 2022 年 7 月 25 日
Hi everybody,
how can i set two conditions in one line in the regexp function of matlab? E.g. my input string array is:
str = {'strawberry/banana#(';'apple#,melon*cherry';'apple_banana_cherry'};
I only want to get the starting index of strings that 1. start with 'apple' and 2. end with 'cherry'. In this case it wold be the second and third string of which i'd like to get the index number.
Thanks in andvance!

採用された回答

Chunru
Chunru 2022 年 7 月 25 日
str = {'strawberry/banana#(';'apple#,melon*cherry';'apple_banana_cherry'};
s = regexp(str, '^apple.*(cherry)$', 'match');
idx = cellfun(@(x) ~isempty(x), s)
idx = 3×1 logical array
0 1 1
  1 件のコメント
Lorenz
Lorenz 2022 年 7 月 25 日
Thanks again for your quick reply @Chunru!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by