php - Basic Regular Expression for -


for reason stuck making past extremely basic regular expressions.

i'm trying make regular expression kind of looks url. want basic checking.

i match following patterns x "something".

x://x.x

x://x.x... etc.

x.x

x.x... etc

if string contains 1 of these patterns, sufficient checking me. way url www.example.com:8888 still match. have tried many different regex combinations preg_match , cannot seem behave way want to. have consulted many other related regex questions on readings have not helped me.

any help? happy provide more information if don't know else need.

it takes practice here 1 made using regex tester (http://www.regextester.com/) check pattern:

^.+(:\/\/|\.)([a-za-z0-9]+\.)+.+ 

my approach build pattern beginning , add on 1 piece @ time. cheatsheet extremely helpful remembering http://www.cheatography.com/davechild/cheat-sheets/regular-expressions/ is.

basically pattern starts @ beginning of string , checks characters followed either :// or . checks groupings of letters , numbers followed . ending number of characters.

the pattern improved groupings not pass on invalid characters. 1 quick , dirty. replace first , last . characters valid.

update

per comments here updated pattern:

^.+?(:\/\/|\.)?([a-za-z0-9]+?\.)+.+ 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -