Can someone explain this regexp command?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have some code:
expr = '<Placemark>.*?</Placemark>';
objectStrings = regexp(txt,expr,'match');
This works exactly as I would like it to. However, I am not fundamentally understanding what Matlab is doing, specifically when I see the .*? I have pored over the documentation, but I am just not understanding. Would someone please be kind enough to explain what is happening?
1 commentaire
Réponses (1)
Stephen23
le 17 Mai 2017
Modifié(e) : Stephen23
le 17 Mai 2017
It is quite simple:
<Placemark> % match literal string
.* % match any characters, any number of times
? % makes the previous quantifier lazy (ie *)
</Placemark> % match literal string
The MATLAB documentation explains how regular expressions work:
And we find it explains all of those parts of your regular expression:
- angle brackets are not special characters, therefore the "placemark" parts are interpreted literally.
- " expr* 0 or more times consecutively."
- " exprq? Lazy expression: match as few characters as necessary."
0 commentaires
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!