Need help making very specific regexp
조회 수: 3 (최근 30일)
이전 댓글 표시
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
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!