| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/zh-CN/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);
// Expected output: Array ["T", "I"]
match(regexp)
g g match() RegExp.prototype.exec() String.prototype.match Symbol.match RegExp.prototype[Symbol.match]()
RegExp RegExp.prototype.test()RegExp.prototype.exec()RegExp.prototype.exec() String.prototype.matchAll() 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) input
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 = "";
str.match(); // [""]
[Symbol.match]() RegExp match() 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 new RegExp(regexp) RegExp
const str1 =
"NaN JavaScript Infinity -Infinity +Infinity";
const str2 = " 65 63 ";
const str3 = " null void";
str1.match(""); // [""]
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"]
console.log("123".match("1.3")); // [ "123" ]
.
console.log("123".match("1\\.3")); // null
| ECMAScript 2027 LanguageSpecification # sec-string.prototype.match |
StringString.prototype.anchor()String.prototype.at()String.prototype.big()String.prototype.blink()String.prototype.bold()String.prototype.charAt()String.prototype.charCodeAt()String.prototype.codePointAt()String.prototype.concat()String.prototype.endsWith()String.prototype.fixed()String.prototype.fontcolor()String.prototype.fontsize()String.prototype.includes()String.prototype.indexOf()String.prototype.isWellFormed()String.prototype.italics()String.prototype.lastIndexOf()String.prototype.link()String.prototype.localeCompare()String.prototype.match()String.prototype.matchAll()String.prototype.normalize()String.prototype.padEnd()String.prototype.padStart()String.prototype.repeat()String.prototype.replace()String.prototype.replaceAll()String.prototype.search()String.prototype.slice()String.prototype.small()String.prototype.split()String.prototype.startsWith()String.prototype.strike()String.prototype.sub()String.prototype.substr()String.prototype.substring()String.prototype.sup()String.prototype.toLocaleLowerCase()String.prototype.toLocaleUpperCase()String.prototype.toLowerCase()String.prototype.toString()String.prototype.toUpperCase()String.prototype.toWellFormed()String.prototype.trim()String.prototype.trimEnd()String.prototype.trimStart()String.prototype.valueOf()String.prototype[Symbol.iterator]()Object/FunctionObject.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()| Web Proxy Viewer | New URL | Original Page |