String.prototype.match()

0
12K

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
Decision Making and Problem Solving
How does critical thinking improve leadership?
The studio is quiet. There is a specific kind of silence that happens right before a take....
By Michael Pokrovski 2026-06-27 13:51:00 0 422
Mental Health
Psychosis: Cannabis
According to current studies, cannabis use is associated with increased risk of psychotic...
By Kelsey Rodriguez 2023-05-31 18:03:47 0 12K
Decision Making and Problem Solving
How do teachers encourage creative problem-solving?
The Architecture of the Intellectual Pivot The mind is a pattern-making machine. It is...
By Michael Pokrovski 2026-07-09 10:02:27 0 326
Business
How Can I Connect with Other Indie Hackers for Support and Collaboration?
Building a successful indie business can often feel like a lonely journey. As you work to develop...
By Dacey Rankins 2025-02-17 16:45:14 0 18K
Business
What Is the Future of Office Automation?
The office has never been a static environment. It evolves quietly, shaped by tools,...
By Dacey Rankins 2026-04-28 16:27:02 0 3K

BigMoney.VIP Powered by Hosting Pokrov