javascript - Regex to detect urls without www and http -
could update regex match next requirements
- must match urls without www , http
- if query contains - match too
- url ends when space or comma(,) or string end meet
match topleveldomains list
var srg = new regexp(/(^|[\s])([\w\.]+\.(com|cc|net))/ig);
for sample, must match:
jsfiddle.net jmitty.cc:8080/test3s.html www.ru,sample.com,google.com/?l=en very.secure.dotster.com/i?ewe
as result need
<a>jsfiddle.net</a> <a>jmitty.cc:8080/test3s.html</a> <a>www.ru</a>,<a>sample.com</a>,<a>google.com/?l=en</a> <a>very.secure.dotster.com/i?ewe</a>
fiddle http://jsfiddle.net/tynu7/
well, guess can change little things in regex:
([\w\.]+\.(?:com|cc|net|ru)[^,\s]*)
replace by:
<a href="$1" target="_blank">$1</a>
i'm not sure why having (^|[\s])
@ beginning , didn't seem useful me, removed it. if had reasons, can put back.
i added ru
extensions match www.ru
required , added [^,\s]*
continue matching until comma or space encountered.
your updated fiddle here.
Comments
Post a Comment