* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
1.6 KiB
1.6 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d7db6367417b2b2512b9b | 用惰性匹配来查找字符 | 1 | 301341 | find-characters-with-lazy-matching |
--description--
在正则表达式中,贪婪
匹配会匹配到符合正则表达式匹配模式的字符串的最长可能部分,并将其作为匹配项返回。另一种方案称为懒惰
匹配,它会匹配到满足正则表达式的字符串的最小可能部分。
可以将正则表达式/t[a-z]*i/
应用于字符串"titanic"
。这个正则表达式是一个以t
开始,以i
结束,并且中间有一些字母的匹配模式。
正则表达式默认是贪婪
匹配,因此匹配返回为["titani"]
。它会匹配到适合该匹配模式的最大子字符串。
但是,你可以使用?
字符来将其变成懒惰
匹配。调整后的正则表达式/t[a-z]*?i/
匹配字符串"titanic"
返回["ti"]
。
注意
应该避免使用正则表达式解析 HTML,但是可以用正则表达式匹配 HTML 字符串。
--instructions--
修复正则表达式/<.*>/
,让它返回 HTML 标签<h1>
,而不是文本"<h1>Winter is coming</h1>"
。请记得在正则表达式中使用通配符.
来匹配任意字符。
--hints--
结果
变量应该是一个包含<h1>
的数组。
assert(result[0] == '<h1>');
--seed--
--seed-contents--
let text = "<h1>Winter is coming</h1>";
let myRegex = /<.*>/; // Change this line
let result = text.match(myRegex);
--solutions--
let text = "<h1>Winter is coming</h1>";
let myRegex = /<.*?>/; // Change this line
let result = text.match(myRegex);