How to parse information between two strings using regular expressions?
23 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I am trying to parse some information contained between the two strings "<sample>" and "</sample>" . I am new to regular expressions and would like to know what expression suits my requirement. The strings i mentioned have some operators in them. This is making the job difficult.
Regards, Math
2 commentaires
Guillaume
le 1 Déc 2014
If you need more help than Thorsten's answer (which pretty much tells you everything that there is to it), then show us your current regular expression.
Réponse acceptée
Andrei Bobrov
le 2 Déc 2014
Modifié(e) : Andrei Bobrov
le 2 Déc 2014
str = '<sample>a,b,c</sample>';
out = regexp(str,'((?<=<sample>).*(?=<\/sample>))','match')
or
t = regexp(str,'<(|\/)sample>','splite')
out = t(~cellfun(@isempty,t))
0 commentaires
Plus de réponses (2)
Niels
le 2 Déc 2014
Alternatively, you may also consider using regexprep instead of regexp.
>> extract = regexprep(str,pat,'')
extract =
a,b,c
Voir également
Catégories
En savoir plus sur Characters and Strings 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!