Search - Regular Expression Search in JavaScript

<script type="text/javascript">

    var myString = new String("This is a test");

    var myRegExp = /test/;

    var answerIdx = myString.search(myRegExp);

    if(answerIdx == -1){
      document.write('No matches were found');
    }else{
      document.write('Your search string was found starting at: ' + answerIdx);
    }
  
    </script>