freeCodeCamp/guide/chinese/certifications/javascript-algorithms-and-d.../regular-expressions/find-characters-with-lazy-m.../index.md

452 B
Raw Blame History

title localeTitle
Find Characters with Lazy Matching 查找具有延迟匹配的字符

查找具有延迟匹配的字符

Challange

修复regex /<.*>/以返回HTML标记<h1>而不是文本<h1>Winter is coming</h1> 。记住通配符。在正则表达式中匹配任何字符。

解:

let text = "<h1>Winter is coming</h1>"; 
 let myRegex = /<h1>?/; // it's the answer! 
 let result = text.match(myRegex);