Test case details

Preparation Code

<script> var regex = /regex/; var str = 'This is a regex string.'; </script>

Test cases

Test #1

if (regex.exec(str) !== null) {  // String matches regex }

Test #2

if (str.match(regex) !== null) {  // String matches regex }

Test #3

if (regex.test(str) !== false) {  // String matches regex }

Test #4

if (str.search(regex) !== -1) {  // String matches regex }

Test #5

if (str.indexOf(regex) !== -1) {  // String matches regex }