String.prototype.match()

0
7K

A regular expression object, or any object that has a Symbol.match method.

If regexp is not a RegExp object and does not have a Symbol.match method, it is implicitly converted to a RegExp by using new RegExp(regexp).

If you don't give any parameter and use the match() method directly, you will get an Array with an empty string: [""], because this is equivalent to match(/(?:)/).

Return value

An Array whose contents depend on the presence or absence of the global (g) flag, or null if no matches are found.

  • If the g flag is used, all results matching the complete regular expression will be returned, but capturing groups are not included.
  • If the g flag is not used, only the first complete match and its related capturing groups are returned. In this case, match() will return the same result as RegExp.prototype.exec() (an array with some extra properties).

Description

The implementation of String.prototype.match itself is very simple — it simply calls the Symbol.match method of the argument with the string as the first parameter. The actual implementation comes from RegExp.prototype[@@match]().

For more information about the semantics of match() when a regex is passed, see RegExp.prototype[@@match]().

Căutare
Categorii
Citeste mai mult
Camps
Embracing Adventure: The Magic of Recreational Camping
Embracing Adventure: The Magic of Recreational Camping Introduction: Amidst the hustle and...
By Leonard Pokrovski 2024-05-09 10:10:04 0 11K
Educaţie
The Importance of Art Education: Nurturing Creativity and Innovation
Art education plays a significant role in the holistic development of individuals, fostering...
By Dacey Rankins 2025-01-24 18:13:07 0 6K
Horror
The Thing. (1982)
A research team in Antarctica is hunted by a shape-shifting alien that assumes the appearance of...
By Leonard Pokrovski 2023-02-27 16:32:44 0 16K
Conventions
The World of Game Conventions: Celebrating Gaming Culture and Community
Game conventions are the epicenter of gaming culture, offering enthusiasts a chance to gather,...
By Dacey Rankins 2024-12-02 14:55:38 0 6K
Dentistry
The Importance of Dentistry: Keeping Smiles Healthy
Dentistry plays a crucial role in maintaining overall health and well-being. While often...
By Dacey Rankins 2024-10-10 15:29:40 0 18K
image/svg+xml


BigMoney.VIP Powered by Hosting Pokrov