How can I correctly check if a string does NOT contain a specific word?

前端 未结 6 1307
一个人的身影
一个人的身影 2021-01-11 15:01

I am currently trying to figure out how to solve the above named problem. Specifically I want to check if the string does not contain the word \"stream\" both in ca

6条回答
  •  旧巷少年郎
    2021-01-11 15:25

    this is a operation you can do in regex:

    const testString1 = "I might contain the word StReAm and it might be capitalized any way.";
    const testString2 = "I might contain the word steam and it might be capitalized any way.";
    const re = /stream/i
    console.log( !!(testString1.match(re) ));
    console.log( !!(testString2.match(re) ))

提交回复
热议问题