Need help making very specific regexp

1 view (last 30 days)
Jay
Jay on 9 May 2012
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!

Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!