ruby - Capturing just a part of the website -


i have regular expression this;

/(?:http[s]?:\/\/)?(?:www\.)?(.*)/

i want capture domain part of website disregard protocol. so, regular expression works, captures empty spaces. empty space here come ? if understand this, helpful me.

if feed following strings match,

inputs:

http://google.com https://www.simplecms.com www.facebook.com gmail.com 

outputs:

match 1 1.  google.com match 2 1.    match 3 1.  simplecms.com match 4 1.    match 5 1.  facebook.com match 6 1.    match 7 1.  gmail.com match 8 1.    match 9 1.     

if @ output, job captures empty string. sure there better way capture thing.

try adding start/end of line beginning , end of regex. ^ @ beginning $ @ end, matches on line. think happening regex seeing returns , matching those.

try: ^(?:http[s]?:\/\/)?(?:www\.)?(.*)$ (note: may have escape things depending on language).

using example provided set quick test show matches here.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

mysql - Pass value between different pages (form) with PHP -