php - Regular expression that matches specific url format in textarea field -


basically want have html textarea field, user can write comment. if user writes url, want highlight url. example bellow:

"hi! comment. link http://www.google.com , comment continues."

i want regular expression match urls formatted follows:

  1. http://google.com
  2. http://www.google.com
  3. www.google.com

i don't want match urls formatted follows

  1. google.com
  2. www.com

so far regular expression looks this:

/(http)?(s)?(:\/\/)?((w*\.)([a-za-z0-9])([-\w]+\.)+([^\s\.]+[^\s]*)+[^,.\s])/

but problem cannot match http://google.com (1) of list above.

i know topic may marked duplicate , apology wasn't able find need anywhere. appreciated :)


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -