Effacer les filtres
Effacer les filtres

regexp function - get index of string with two conditions

2 vues (au cours des 30 derniers jours)
Lorenz
Lorenz le 25 Juil 2022
Commenté : Lorenz le 25 Juil 2022
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!

Réponse acceptée

Chunru
Chunru le 25 Juil 2022
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

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by