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\/?$/ 

regular expression visualization

  • http or https
  • www., m. or no subdomain
  • facebook.com

demo

edit include optional trailing backslash


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -