ruby - Regex to match look before this or that -
ruby - Regex to match look before this or that -
i'm attempting match within of url.
www.facebook.com http://www.facebook.com http://facebook.com
should homecoming facebook
my current regex (?<=www\.|http:\/\/).*(?=\.[a-za-z]{2,4})
this matches correctly except 1 http://www., match www.facebook
how create regex before match lastly occurrence of either wwworhttp://
rubular link
in ruby, can utilize this:
(?i)^(?:http://)?(?:\w+\.)?\k\w+(?=\.[a-z]{2,4}$) see demo.
^ asserts @ origin of string (?i) puts in case-insensitive mode (?:http://)? optionally matches http:// part (?:\w+\.)? optionally matches subdomain \k keeps out have matched match returned \w+ matches facebook the (?=\.[a-z]{2,4}$) lookahead checks followed domain end of string. ruby regex
Comments
Post a Comment