| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/match | [Back] [Original] |
Get to know MDN better
const paragraph = "The quick brown fox jumps over the lazy dog. It barked.";
const regex = /[A-Z]/g;
const found = paragraph.match(regex);
console.log(found);
// : Array ["T", "I"]
match(regexp)
g g match() RegExp.prototype.exec() String.prototype.match Symbol.match RegExp.prototype[Symbol.match]()
match() RegExp.prototype[Symbol.match]()
match() "Chapter" 1 0
i
const str = "For more information, see Chapter 3.4.5.1";
const re = /see (chapter \d+(\.\d)*)/i;
const found = str.match(re);
console.log(found);
// [
// 'see Chapter 3.4.5.1',
// 'Chapter 3.4.5.1',
// '.1',
// index: 22,
// input: 'For more information, see Chapter 3.4.5.1',
// groups: undefined
// ]
'see Chapter 3.4.5.1' 'Chapter 3.4.5.1' (chapter \d+(\.\d)*) '.1' (\.\d) index (22) 0 input
g i match() A E a e
const str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
const regexp = /[a-e]/gi;
const matches = str.match(regexp);
console.log(matches);
// ['A', 'B', 'C', 'D', 'E', 'a', 'b', 'c', 'd', 'e']
"fox" "cat" animal
const paragraph = "The quick brown fox jumps over the lazy dog. It barked.";
const capturingRegex = /(?<animal>fox|cat) jumps over/;
const found = paragraph.match(capturingRegex);
console.log(found.groups); // {animal: "fox"}
const str = "Nothing will come of nothing.";
str.match(); // returns [""]
[Symbol.match]() RegExp Symbol.match Symbol.match match()
const str = "Hmm, this is interesting.";
str.match({
[Symbol.match](str) {
return ["Yes, it's interesting."];
},
}); // returns ["Yes, it's interesting."]
regexp RegExp new RegExp(regexp)
const str1 =
"All numbers except NaN satisfy <= Infinity and >= -Infinity in JavaScript.";
const str2 =
"My grandfather is 65 years old and My grandmother is 63 years old.";
const 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"]
str2.match(65); // ["65"]
str3.match(null); // ["null"]
console.log("123".match("1.3")); // [ "123" ]
.
console.log("123".match("1\\.3")); // null
| ECMAScript 2027 LanguageSpecification # sec-string.prototype.match |
Stringanchor()at()big()blink()bold()charAt()charCodeAt()codePointAt()concat()endsWith()fixed()fontcolor()fontsize()includes()indexOf()isWellFormed()italics()lastIndexOf()link()localeCompare()match()matchAll()normalize()padEnd()padStart()repeat()replace()replaceAll()search()slice()small()split()startsWith()strike()sub()substr()substring()sup()toLocaleLowerCase()toLocaleUpperCase()toLowerCase()toString()toUpperCase()toWellFormed()trim()trimEnd()trimStart()valueOf()[Symbol.iterator]()Object/Function| Web Proxy Viewer | New URL | Original Page |