在Matlab正则表达式中提取URL

时间:2018-10-15 10:51:08

标签: regex matlab

我正试图熟悉regexp。尽管如此,我仍然遇到一些问题。我只想提取以下网址:

regularexpression = '';       
script = ['I <I>used</I> <B>to</B> visit <THE> website <A HREF=www.lichess.org>twice a day</A>. ' ...
'Visit <I>the website</I> <A HREF=www.bing.com>or alternatively</A> just <A HREF=www.google.com> for more information</A>.']
x = regexp(script,regularexpression,'match')

这应该提供一个1X3的单元格数组{'www.lichess.org'} {'www.bing.com'} {'www.google.com'}

1 个答案:

答案 0 :(得分:0)

regularexpression = 'www\.[^>]*'; 
script = ['I <I>used</I> <B>to</B> visit <THE> website <A HREF=www.lichess.org>twice a day</A>. ' ...
'Visit <I>the website</I> <A HREF=www.bing.com>or alternatively</A> just <A HREF=www.google.com> for more information</A>.']
x = regexp(script,regularexpression,'match')

输出:

  1×3 cell array

    {'www.lichess.org'}    {'www.bing.com'}    {'www.google.com'}