I have these possible folder names in a url:
firstname+lastname
firstname-lastname
firstname lastname
Firstname+Lastname
I need a way to catch these, the common element would be firstname and lastname (so I don't care about the + - or space), but I do need to convert them toLowerCase();
Can this be done with a regex? (I am not particularly sophisticated in my use of regex, I can use basic match() functions.
My other thought was to store these variants in an array and return true if any of the items match one of the array items.
I was looking at this solution: http://ift.tt/1EuzboC
In this case though I think my array and statement would look something like this:
var strArray = ['firstname','lastname'];
strArray.toLowerCase();
var href = document.location.href;
var secondaryDir = href.split("/")[4];
if (secondaryDir in strArray){
console.log('Its true!');
// do magic here
}
Not sure if there is a better way to test this?
(I've tagged this question with jquery as that is what I am using, although I think all the code here is vanilla js).
EDIT
Actually I don't need to worry about converting the array to lower case as I can do this against the secondaryDir variable (I think).
Aucun commentaire:
Enregistrer un commentaire