re = /(\bhref="(.*?)\b")(?!.*\1)?/
str = ' <div>
<a href="showthread.php?t=5239160" id="thread_title_5239160">программа для точного определения местоположения любого гаджета</a>
<span class="smallfont" style="white-space:nowrap">(<img class="inlineimg" src="https://static.kharkovforum.com/images/misc/multipage.gif" alt="перейти на страницу" border="0" /> <a href="showthread.php?t=5239160">1</a> <a href="showthread.php?t=5239160&page=2">2</a>)</span>
</div>
<div class="smallfont">
<span style="cursor:pointer" onclick="window.open(\'member.php?u=502041\', \'_self\')">I-am</span>
</div>
'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html