[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/match [Back]  [Original]

String.prototype.match() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

String.prototype.match()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.

match() .

In this article

js
str.match(regexp);

regexp

. RegExp obj , new RegExp(obj) RegExp . match() , :[""] Array .

, Array . null .

g , str.match() RegExp.exec() . Array input . index .

g , Array . . null .

: RegExp

match()

, match() 'Chapter' 1 , , . i , .

js
var str = "For more information, see Chapter 3.4.5.1";
var re = /see (chapter \d+(\.\d)*)/i;
var found = str.match(re);

console.log(found);

// logs [ 'see Chapter 3.4.5.1',
//        'Chapter 3.4.5.1',
//        '.1',
//        index: 22,
//        input: 'For more information, see Chapter 3.4.5.1' ]

// 'see Chapter 3.4.5.1'   .
// 'Chapter 3.4.5.1' '(chapter \d+(\.\d)*)'    .
// '.1'  '(\.\d)'    .
// 'index'  (22)  0   22      .
// 'input'     .

match() (g) / (i)

(g) / (i) match() . A E a e .

js
var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var regexp = /[A-E]/gi;
var matches_array = str.match(regexp);

console.log(matches_array);
// ['A', 'B', 'C', 'D', 'E', 'a', 'b', 'c', 'd', 'e']

match()

js
var str = "Nothing will come of nothing.";

str.match(); // returns [""]

(Number), new RegExp(obj) RegExp . , RegExp() .

js
var str1 =
    "NaN means not a number. Infinity contains -Infinity and +Infinity in JavaScript.",
  str2 = "My grandfather is 65 years old and My grandmother is 63 years old.",
  str3 = "The contract was declared null and void.";
str1.match("number"); // "number" . ["number"] .
str1.match(NaN); // NaN  . ["NaN"] .
str1.match(Infinity); // Infinity  . ["Infinity"] .
str1.match(+Infinity); // ["Infinity"] .
str1.match(-Infinity); // ["-Infinity"] .
str2.match(65); // ["65"] 
str2.match(+65); //    . ["65"] .
str3.match(null); // ["null"] .

Specification
ECMAScript 2027 LanguageSpecification
# sec-string.prototype.match


Web Proxy Viewer  |  New URL  |  Original Page