Skip to content
Akin C edited this page Jan 1, 2020 · 18 revisions

Welcome to the Javascript-RegExp-methods-match-and-test- wiki!

This repository is part of a larger project!

◀️ PREVIOUS PROJECT| NEXT PROJECT ▶️


With the help of RegExp constructor, regular expressions should be possible to use.

Two methods should be of interest here:

  1. test
  2. match

🔖 It should be clarified that match is a String method and not a RegExp.

The big difference between the two methods should be that test prints a Boolean value to check for a match, while match should print an array or null if it is used.

An example follows for both cases:

var myString = "Hello World!";
var myRegExp = new RegExp("Hello");

//---test---//

// Searches for a match with the word "Hello" within "Hello World"
var result = myRegExp.test(myString);
// Outputs: true
console.log(result);


//---match---//

// Searches for a match with the word "Hello" within "Hello World"
result = myString.match(myRegExp);
// Outputs: ["Hello", index: 0, input: "Hello World!", groups: undefined]
console.log(result);

The output for the method match should be read as follows:

  • "Hello" should be the match
  • index should be the position where the match was found
  • input should be the text in which the search was done

Personal Note 😉:

For this mini project a research for the output element "groups" was not needed, 
but there should be a link which could contain more information found in 
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Groups_and_Ranges

TODO: Flags

STILL IN WORK!

Clone this wiki locally