HTML:
<textarea name="test">
http://google.com/
https://google.com/
http://www.google.com
www.google.com/
[url=http://google.com/]test[/url]
text
</textarea>
jQuery:
$('button').click(function() {
if ($('textarea[name="test"]').val().match(/\[url/)) {
alert('links exist');
}
});
什么样的正则表达式会匹配我在我的每个 URL 实例<textarea>
?
jsFiddle:http: //jsfiddle.net/5Z8AU/