That is, the character 's' is matched in the string. To match with all s, use g modifier in this way:
const pattern = /s/g;
Now the output should be:
The g (stands to global) modifier is used to find all matches, instead of stopping after the first match.
Also we can use the i modifier to allow matching go case-insensitive. For example, let me modify the above example:
List of 's' found in the String:
You can see the output. This time the S which is in uppercase also has returned, because I have applied the i modifier to force the match go case-insensitive.
The search_pattern argument is required, which indicates to a regular expression that will be used to find the match in the specified string.
The match() method returns an array, that contains all matches as its elements. Otherwise returns null.
« Previous Tutorial Next Tutorial »
Like/Share Us on Facebook 😋