String.prototype.match()

0
9K

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

Search
Categories
Read More
Environment
The 10 most environmentally friendly countries
The site for expats InterNations interviewed about 15 thousand people who left their home...
By FWhoop Xelqua 2022-12-24 15:35:08 0 19K
Programming
How to Get Normally Distributed Random Numbers With NumPy
Probability distributions describe the likelihood of all possible outcomes of an event or...
By Jesse Thomas 2023-05-02 20:46:08 0 9K
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 19K
Business
Why does a start-up business need marketing?
Why does a start-up business need marketing? It seems that the English-language term...
By Leonard Pokrovski 2024-08-30 00:02:17 0 17K
Business
What Do You Like Most About Working for This Company?
During a job interview, one insightful question candidates often ask is: "What do you like most...
By Dacey Rankins 2025-06-24 15:32:48 0 3K

BigMoney.VIP Powered by Hosting Pokrov