Need help making very specific regexp
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have list of strings to apply a regular expression to. Some of them have HTML tags, some don't. It basically looks like this:
astring={'<HTML><FONT color="blue">taggedtext</Font></HTML>';'someothertext1';'someothertext2'...etc}
I'm trying to right a regular expression to get the 'taggedtext' if there are HTML tags and get 'someothertext1', etc. if there are not tags. I'm interested in doing this in ONE expression, I've already found plenty of ways to do it with other functions or multiple regular expressions.
This is the closest I've come:
expressyoself='(<?)(?(1)>(\w+)<{1}|(\w+){1})'
[mat tok]=regexp(astring,expressyoself,'match','tokens','warnings');
Which returns the correct values for all the non-tagged items, but returns the following for the tagged ones (cell array)
'HTML' 'FONT' 'color' 'blue' 'taggedtext' 'Font' 'HTML'
If anyone can figure this out, it'd be greatly appreciated.
Thanks!
0 commentaires
Réponses (0)
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!