Need help making very specific regexp
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (0)
Vedere anche
Categorie
Scopri di più su Characters and Strings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!