String.prototype.match()

0
8K

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
Business
What Platforms Are Popular in the Creator Economy?
The Creator Economy has exploded in recent years, with countless platforms offering creators new...
By Dacey Rankins 2025-02-24 16:00:08 0 7K
Programming
Display Data from Python to HTML
When making a web application, you're probably thinking if displaying data from Python to HTML is...
By Jesse Thomas 2023-01-26 19:18:03 0 10K
Men's Health
Men's Health: Key Aspects and Tips for a Longer, Healthier Life
Men's health is a crucial aspect of overall well-being, encompassing physical, mental, and...
By Dacey Rankins 2024-11-21 15:52:31 0 7K
Business
Can Indie Hacking Lead to a Sustainable Full-Time Income?
Indie hacking, the practice of building and growing small, independent businesses without the...
By Dacey Rankins 2025-02-17 16:41:42 0 10K
Central America
Central America
Central America (Spanish: América Central) is a region located between the North American...
By FWhoop Xelqua 2023-02-21 13:37:24 0 17K
image/svg+xml


BigMoney.VIP Powered by Hosting Pokrov