TypeScript: Check occurrence of element in string with Regex

function find (stringToTest) {
  const a = stringToTest.match(new RegExp(":", "g"));
  const b = stringToTest.match(new RegExp("=", "g"));
  if (a?.length > 1 || b?.length > 1) return true;
  return false;
}

console.log(find("hello:world=")); // false
console.log(find("hello world")); // false
console.log(find("hello world====")); // true

Code Example Quizzes

Related Code Examples