- case is significant. ( "liquid, X" the lower case "l" is a typo.)
- space is significant
find a string using regular expression using a special condition
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello All,
How to find the line number for the string "liquid, X" in a text file, if and only if the line immidiately before its occarance contains the string "Com(6 ,C4 )"
Molar Distributions Com(5 ,C3 ) Com(6 ,C4 ) Com(7 ,C5 ) Com(8 ,C6 )
Liquid, X Inserted ------------ ------------ ------------ ------------
0 commentaires
Réponse acceptée
per isakson
le 9 Nov 2019
Modifié(e) : per isakson
le 9 Nov 2019
Assumptions regarding the search terms
Try
%%
chr = fileread( 'RR.txt' );
cac = strsplit( chr, '\r?\n', 'DelimiterType', 'RegularExpression' );
%%
is_Com6C4 = contains( cac, 'Com(6 ,C4 )' );
is_Liquid = startsWith( cac, 'Liquid, X' );
%%
ix_searched = find( [ false, is_Com6C4 ] & [ is_Liquid, false ] );
where RR.txt contains
Her old collecting she considered discovered. So at parties he warrant oh staying.
Square new horses and put better end. Sincerity collected happiness do is contented.
Liquid, X Inserted ------------ ------------ ------------ ------------
Molar Distributions Com(5 ,C3 ) Com(6 ,C4 ) Com(7 ,C5 ) Com(8 ,C6 )
Sigh ever way now many. Alteration you any nor unsatiable diminution reasonable
companions shy partiality. Leaf by left deal mile oh if easy. Added woman first get led
joy not early jokes.
Molar Distributions Com(5 ,C3 ) Com(6 ,C4 ) Com(7 ,C5 ) Com(8 ,C6 )
Liquid, X Inserted ------------ ------------ ------------ ------------
Not far stuff she think the jokes. Going as by do known noise he wrote round leave.
Warmly put branch people narrow see. Winding its waiting yet parlors married own
Molar Distributions Com(5 ,C3 ) Com(6 ,C4 ) Com(7 ,C5 ) Com(8 ,C6 )
feeling. Marry fruit do spite jokes an times. Whether at it unknown warrant herself
Liquid, X Inserted ------------ ------------ ------------ ------------
winding if. Him same none name sake had post love. An busy feel form hand am up help.
Parties it brother amongst an fortune of. Twenty behind wicket why age now itself ten
If the assumptions are not fullfilled, regular expressions might be needed.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Environment and Settings dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!