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]().

Zoeken
Categorieën
Read More
Miniatures
The Best Miniatures Board Games in 2024
The Best Miniatures Board Games in 2024 When players are introduced to a new board...
By Leonard Pokrovski 2024-04-05 21:49:19 0 28K
Personal Finance
7 reasons not to discuss personal finances with your partner
Heroine Spending diary She shared that she and her husband save for housing together, but do not...
By Dacey Rankins 2024-10-23 16:00:22 0 27K
Economics
What is the cost of borrowing?
What Is the Cost of Borrowing? The cost of borrowing is the total amount a person or business...
By Leonard Pokrovski 2026-08-10 00:16:55 0 1K
Computer Science
Computer Science
Informatics is the science of methods and processes of collecting, storing,...
By Michael Pokrovski 2024-03-21 23:29:27 0 31K
Economics
What is cost-benefit analysis?
What Is Cost-Benefit Analysis? A disciplined way to think—or a seductive illusion of...
By Leonard Pokrovski 2026-05-05 09:02:55 0 5K

BigMoney.VIP Powered by Hosting Pokrov