* fix: remove isHidden flag from frontmatter * fix: add isUpcomingChange Co-authored-by: Ahmad Abdolsaheb <ahmad.abdolsaheb@gmail.com> * feat: hide blocks not challenges Co-authored-by: Ahmad Abdolsaheb <ahmad.abdolsaheb@gmail.com> Co-authored-by: Ahmad Abdolsaheb <ahmad.abdolsaheb@gmail.com>
2.3 KiB
2.3 KiB
id, title, challengeType, forumTopicId
id | title | challengeType | forumTopicId |
---|---|---|---|
587d7db6367417b2b2512b9b | Find Characters with Lazy Matching | 1 | 301341 |
Description
/t[a-z]*i/
to the string "titanic"
. This regex is basically a pattern that starts with t
, ends with i
, and has some letters in between.
Regular expressions are by default greedy, so the match would return ["titani"]
. It finds the largest sub-string possible to fit the pattern.
However, you can use the ?
character to change it to lazy matching. "titanic"
matched against the adjusted regex of /t[a-z]*?i/
returns ["ti"]
.
NoteParsing HTML with regular expressions should be avoided, but pattern matching an HTML string with regular expressions is completely fine.
Instructions
/<.*>/
to return the HTML tag <h1>
and not the text "<h1>Winter is coming</h1>"
. Remember the wildcard .
in a regular expression matches any character.
Tests
tests:
- text: The <code>result</code> variable should be an array with <code><h1></code> in it
testString: assert(result[0] == '<h1>');
- text: <code>myRegex</code> should use lazy matching
testString: assert(/\?/g.test(myRegex));
- text: <code>myRegex</code></code> should not include the string 'h1'
testString: assert(!myRegex.source.match('h1'));
Challenge Seed
let text = "<h1>Winter is coming</h1>";
let myRegex = /<.*>/; // Change this line
let result = text.match(myRegex);
Solution
let text = "<h1>Winter is coming</h1>";
let myRegex = /<.*?>/; // Change this line
let result = text.match(myRegex);