Url regex that can work without http://, https:// -


i using regex parse user's profile text , spit out links:

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

how modified match common urls without http:// https://? (or if have better regex, that's fine)

e.g. matches:

twitch.tv/myusername youtube.com/myusername twitter.com/myusername steamcommunity.com/id/myusername 

will not match:

blah.blah 

for working example, noticed slack has url detector. enter image description here

update: 1 seems closer want still matches blah.blah

^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$ 

http://www.regextester.com/?fam=97352


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -