Baseline Widely available
test()
ë©ìëë 주ì´ì§ 문ìì´ì´ ì ê· ííìì ë§ì¡±íëì§ íë³íê³ , ê·¸ ì¬ë¶ë¥¼ true
ëë false
ë¡ ë°íí©ëë¤.
const str = "table football";
const regex = new RegExp("foo*");
const globalRegex = new RegExp("foo*", "g");
console.log(regex.test(str));
// Expected output: true
console.log(globalRegex.lastIndex);
// Expected output: 0
console.log(globalRegex.test(str));
// Expected output: true
console.log(globalRegex.lastIndex);
// Expected output: 9
console.log(globalRegex.test(str));
// Expected output: false
구문 매ê°ë³ì
str
ì ê· ííì ì¼ì¹ë¥¼ ìíí 문ìì´.
주ì´ì§ 문ìì´ str
ì¤ ì ê· ííìì´ ì¼ì¹íë ë¶ë¶ì´ ìì¼ë©´ true
, ìëë©´, false
.
í¨í´ì´ 문ìì´ ë´ì ì¡´ì¬íëì§ì ëí ì¬ë¶ë¥¼ ììë³´ê³ ì í ë test()
를 ì¬ì©íì¸ì. ì¼ì¹ì ìì¹ ì¸ë±ì¤, ëë ì¼ì¹íì§ ìì¼ë©´ -1
ì ë°ííë String.prototype.search()
ì ë¬ë¦¬ test()
ë ë¶ë¦¬ì¸ì ë°íí©ëë¤.
ë ë리ì§ë§ ë ë§ì ì ë³´ê° íìíë©´ exec()
ë©ìë를 ì¬ì©íì¸ì. (String.prototype.match()
ë©ìëì ë¹ì·í©ëë¤.)
exec()
ì²ë¼, test()
ë ì ì íì íë그를 ì ê³µí ì ê· ííììì ì¬ë¬ ë² í¸ì¶íë©´ ì´ì ì¼ì¹ ì´íë¶í° íìí©ëë¤. exec()
ì test()
를 í¼ì©í´ ì¬ì©íë ê²½ì°ìë í´ë¹ë©ëë¤.
test()
ì¬ì©í기
문ìì´ì 맨 ì²ìì "hello"
ê° í¬í¨ëëì§ ììë³´ë ê°ë¨í ìì ì½ëì
ëë¤.
const str = "hello world!";
const result = /^hello/.test(str);
console.log(result); // true
ë¤ìì ì¼ì¹ ì¬ë¶ì ë°ë¼ ë¤ë¥¸ ë©ìì§ë¥¼ 기ë¡íë ìì ì ëë¤.
function testInput(re, str) {
let midstring;
if (re.test(str)) {
midstring = "contains";
} else {
midstring = "does not contain";
}
console.log(`${str} ${midstring} ${re.source}`);
}
ì ì íëê·¸ì test()
ì ê· ííìì ì ì íë그를 ì¤ì í ê²½ì°, test()
ë©ìëë ì ê· ííìì lastIndex
를 ì
ë°ì´í¸í©ëë¤. (RegExp.prototype.exec()
ë lastIndex
ìì±ì ì
ë°ì´í¸í©ëë¤.)
test(str)
ì ë í¸ì¶íë©´ str
ê²ìì lastIndex
ë¶í° ê³ì ì§íí©ëë¤. lastIndex
ìì±ì 매 ë² test()
ê° true
를 ë°íí ëë§ë¤ ì¦ê°íê² ë©ëë¤.
ì°¸ê³ :
test()
ê°true
를 ë°ííê¸°ë§ íë©´lastIndex
ë ì´ê¸°íëì§ ììµëë¤. ì¬ì§ì´ ì´ì ê³¼ ë¤ë¥¸ 문ìì´ì 매ê°ë³ìë¡ ì ê³µí´ë ê·¸ë ìµëë¤!
test()
ê° false
를 ë°íí ë lastIndex
ìì±ì´ 0
ì¼ë¡ ì´ê¸°íë©ëë¤.
ì´ íëì ëí ìì ê° ë¤ì ì½ëì ëë¤.
const regex = /foo/g; // the "global" flag is set
// regex.lastIndex is at 0
regex.test("foo"); // true
// regex.lastIndex is now at 3
regex.test("foo"); // false
// regex.lastIndex is at 0
regex.test("barfoo"); // true
// regex.lastIndex is at 6
regex.test("foobar"); //false
// regex.lastIndex is at 0
// (...and so on)
ëª
ì¸ ë¸ë¼ì°ì í¸íì± ê°ì´ 보기
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4