I've been using the .indexOf('') > -1 in order to check whether there's a match in a string. The problem that I'm having is that when I'm performing the match on multiple strings, I get a match on the string for both EIFT and EI (since EIFT contains EI), and so the function returns true for both sentences. What I need is a way for this to only return true for function eIft if the string is "EIFT", but not for EI.
My current code is as follows, and I've been trying to think of ways around this but haven't had any success yet.
function eI(mystring){
return mystring.indexOf("EI") > -1
}
function eIft(mystring){
return mystring.indexOf("EIFT") > -1
}
Thanks!
eIft? It will return false ifmyStringcontainsEIbut notEIFT.EIFTthen it also containsEI, so why shouldn't it match? Are you saying that you want to prefer the longer over the shorter? If so, then search for the longer first.function eIwill return true for string"blah blah eift", when I only wantfunction eIftto return true for"blah blah eift". Hope that clears up your questions :)eIfunction to not returntruewhen it's designed to returntrue. And it's even less clear now that the answer you accepted below would returnfalsefor both functions. Your problem's description is vague. What is the XY Problem