javascript - URL Pattern Matching issue, .+ matches all after -
i matching stored urls current url , having little bit of issue - regex works fine when being matched against url itself, reason sub-directories match (when want direct match of course).
say user stores www.facebook.com, should match both http://www.facebook.com , https://www.facebook.com , does
the problem is matching sub-directories such https://www.facebook.com/events/upcoming etc.
the regex example:
/.+:\/\/www\.facebook\.com/ matches following:
https://www.facebook.com/events/upcoming when should matching
http://www.facebook.com/ https://www.facebook.com/ how can fix seemingly broken regex?
if you're being specific want match, why not reflect in regexp?
/^https?:\/\/(?:(?:www|m)\.)?facebook\.com\/?$/ 
- http or https
- www., m. or no subdomain
- facebook.com
edit include optional trailing backslash
Comments
Post a Comment