/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"]
.
Note/<.*>/
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.
result
variable should be an array with <h1>
in it
testString: assert(result[0] == 'myRegex
should use lazy matching
testString: assert(/\?/g.test(myRegex));
- text: myRegex
should not include the string 'h1'
testString: assert(!myRegex.source.match('h1'));
```