0

I am trying to say if the URL only contains mysite.com and its variations, but nothing else. Variations that I can think of would be:http://, https://, www at the beginning, and a backslash at the end .com/

If it matches one of the above and contains nothing else winFormat = ':homepage'. If anything else - do else, which I have.

I am assuming this has to do with RegEx, which is not my cup of tea.

var winLoc = location.href
var winFormat
if(winLoc.indexOf('error') > -1){
   var winRef = document.referrer.replace(/^.+\.edu/,'').split('/').join(':').replace(/:$/,'');
   winFormat = ':error' + winRef
}
else if ('need this check - if just homepage and/or variations') {
    winFormat = ':homepage'
}
else{
    winFormat = winLoc.replace(/^.+\.edu/,'').split('/').join(':').replace(/:$/,'')
}
RooksStrife
  • 1,647
  • 3
  • 22
  • 54
  • @Mike Samuel This is not a duplicate of that question. I am looking for a very specific word+it's variations. I am not trying to parse the url into different parts. Even if I did break it apart and did if null on the sections - it wouldn't work. I am assuming the pathname would have a "/" if the url = mysite.com/. I need to know if the word+variations exist - if so do this. – RooksStrife May 29 '15 at 15:17
  • if you have only a limited number of matches, to the string, why not just do regular string comparison? `var matches = str == "mysite.com" || str == "mysite.com/" || ...` – Sam I am says Reinstate Monica May 29 '15 at 15:53
  • @SamIam Wouldn't there be a better way though with RegEx. Unless I am missing something. I would have to compare http: //mysite.com, http: //mysite.com/, http: //www.mysite.com, http: //www.mysite.com/, https: //mysite.com, https: //mysite.com/, https: //www.mysite.com, and https: //www.mysite.com/). I am starting to think of doing if pathname has more than just a /. – RooksStrife May 29 '15 at 16:07
  • you can certainly do it with regex too. Your task shouldn't be too hard if you learn the basics of regex. http://rubular.com/ is a good site to play around with regex, and they also have an index of most of the basic regex symbols – Sam I am says Reinstate Monica May 29 '15 at 16:38
  • Going with... `else if (winPat.length <= 1) { winFormat = ':homepage' }` – RooksStrife May 29 '15 at 17:03

0 Answers0