s{( http:// [^\]\})>\s]+ # Won't allow any of these. (?<=[a-zA-Z0-9/&=]) # Must end with one of these. )}{ '' . escape_html_text($1) . '' }xeg; sub escape_html_value # Escapes at least: & => & " => " sub escape_html_text # Escapes at least: & => & < => <