- Regular expressions are expressions that are actually made up of a sequence of characters that later tries to produce a particular search pattern.
- Using these expressions, we may easily look up the data inside any string of several characters bit easily.
- The RegExp object is an object that is particularly used in order to match text (or a string) in accordance with the desired pattern formed.
Syntax: The following syntax is the constructor notation syntax that we use in order to create a regular expression:
new RegExp(string, modifier)
- string: This parameter implies a sequence of characters with or without spacings.
- modifier: This parameter makes the searching easier. It includes “g” (global match), “i” (case-insensitive match) , “m” (multiline match).
Now after analyzing all the facts shown above, let us understand all the above-shown facts with help of an example (coding one) which is enlightened below:
Example 1: In this example, we will create a regular expression using the above-shown syntax and later visualize this in the output itself.
Now let us understand our problem statement which is how to match multiple parts of a string with RegExp using the below-enlightened example
Example 2: In this example create a regular expression using the same syntax which we have seen above and later we will use a method called exec() which will help us to execute our data and calculate the desired result.
First index found at : 19 index number GeeksforGeeks string found lastly at 53 index number