s = "some <a href='sdas'>here</a> other <small>dadas</small>" message = s.sub(/<a[\w\s=']*>/, '*').sub(/<\/a>/, '*') puts message re = /href=['"\w]*/ md = re.match(s) puts md[0]