javascript - What is a good regular expression to match a URL? -



javascript - What is a good regular expression to match a URL? -

this question has reply here:

what best regular look check if string valid url? 36 answers

currently have input box observe url , parse data.

so right now, using:

var urlr = /^(?:([a-za-z]+):)?(\/{0,3})([0-9.\-a-za-z]+) (?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/; var url= content.match(urlr);

the problem is, when come in url www.google.com, not working. when entered http://www.google.com, working.

i not fluent in regular expressions. can help me?

regex if want ensure url starts https

https?:\/\/(www\.)?[-a-za-z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-za-z0-9@:%_\+.~#?&//=]*)

if not require https validation

[-a-za-z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-za-z0-9@:%_\+.~#?&//=]*)

to trial out see http://regexr.com?37i6s or version less restrictive http://regexr.com/39i0i

example javascript implementation

var look = /[-a-za-z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-za-z0-9@:%_\+.~#?&//=]*)?/gi; var regex = new regexp(expression); var t = 'www.google.com'; if (t.match(regex) ) { alert("successful match"); } else { alert("no match"); }

javascript regex

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -