String.match() : match : String JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » String » match »

 

String.match()












Syntax








string.match(regexpression)



The match() method searches the string for the regular expression passed to the method.

The regular expression is made up of a pattern and flags.

The method returns an array containing the matches found in the string.

See RegExp for how to use the regular expression.












<html>
    <script language="JavaScript1.2">
    <!--
    var myString = new String("This is Mr. Right");

    var myRegExp = /sw*/g;

    var answerArray = myString.match(myRegExp);

    if(answerArray == null){
      document.write('No matches were found');
    }else{
      document.write('The following matches were found: <br>');
      for(var i = 0; i < answerArray.length; i++){
        document.write(answerArray[i'<br>');
      }
    }
    document.close();
    -->
    </script>
</html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo String
» match