How to set regexp so that it stops to the first istance?

8 ビュー (過去 30 日間)
pietro 2017 年 6 月 13 日
編集済み: Stephen23 2017 年 6 月 14 日
Hi all,
I need to extract the urls from the following html code and I am using regexp.
a='<option value="">2004-2007</option><option value="" selected>2008-2012</option></select></form></td></tr>';
urls=regexp(a,'(?<=option value.*)http.*html','match');
and the result is:">2004-2007</option><option value="
As you can see the sting extract a string which respects the pattern but it includes two different urls. I need the two following results:
How may I fix this problem?


Stephen23 2017 年 6 月 14 日
編集済み: Stephen23 2017 年 6 月 14 日
You could use a lazy quantifier ? (explained in the regular expression documentation):
>> urls = regexp(a,'(?<=option value.*)http.*?\.html','match');
>> urls{:}
ans =
ans =
A more robust method would be to not match " characters:
>> urls = regexp(a,'(?<=option value=")[^"]+\.html','match');
If you want to experiment with regular expressions then you might like to try my Interactive Regular Expression Tool, which shows the outputs of regexp as your type the parse and match strings. You can download it here:

その他の回答 (0 件)


Help Center および File ExchangeCharacters and Strings についてさらに検索


Community Treasure Hunt

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

Start Hunting!

Translated by