Answer the question
In order to leave comments, you need to log in
Autodetect javascript link
Does anyone have a ready-made solution for auto-detection of a link in a string in javascript?
That is, given the line:
Вот ссылка http://site.com
Вот ссылка <a href="http://site.com" target="_blank">http://site.com</a>
<script>
var str = 'Вот ссылка http://site.com';
var test = str.match("/^((http|https):\/\/)?(www.)?([a-z0-9-]+\.)+[a-z]{2,6}$/");
alert(test);
</script>
Answer the question
In order to leave comments, you need to log in
Change to:
var test = str.match("((http|https):\/\/)?(www.)?([a-z0-9-]+\.)+[a-z]{2,6}");
then like this:
found = /((http|https):\/\/(www\.)?[a-zа-я0-9-]+\.[a-zа-я0-9-]{2,6})/i.exec("текстовая ссылка http://test911.рф");
document.write('found: ' + found);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question