let str, regex, matchIndex; str = `foo A B C D boo`; regex = /A\s+B\s+\C\s+D/g matchIndex = str.search(regex); console.log(matchIndex); //5 regex = /AB\s+\C\s+D/g matchIndex = str.search(regex); console.log(matchIndex); //-1