I used the great tool gskinner.com/RegExr/ to test the regular expression for a string, but I cannot figure out how to implement this in my JavaScript file to return true or false.
The code I have is as follows:
^(http:)\/\/(.+\.)?(stackoverflow)\.
on the url, e.g. http://stackoverflow.com/questions/ask , this will match (according to RegExr) http://stackoverflow.
So, this is great, because I want to try matching the current window.location with this line, but the problem I am facing is that this JavaScript script is not working:
var url = window.location; if ( url.match( /^(http:)\/\/(.+\.)?(stackoverflow)\./ ) ) { alert('this works'); };
Any ideas on what I'm doing wrong here?
Thanks for reading.
Jannis
javascript url regex pattern-matching
Jannis
source share