RegExp Test Method

Use test() to check if a pattern exists in a string.

Preview

Code

<script>
let regex = /cat/;

console.log(regex.test("The cat is here"));
console.log(regex.test("Dog"));
</script>

More JS RegExp Examples (7)