diff --git a/9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/solution.md b/9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/solution.md index 9b3fa187..fb6682b6 100644 --- a/9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/solution.md +++ b/9-regular-expressions/13-regexp-alternation/02-find-matching-bbtags/solution.md @@ -1,14 +1,14 @@ -Opening tag is `pattern:\[(b|url|quote)\]`. +Opening tag is `pattern:\[(b|url|quote)]`. Then to find everything till the closing tag -- let's use the pattern `pattern:.*?` with flag `pattern:s` to match any character including the newline and then add a backreference to the closing tag. -The full pattern: `pattern:\[(b|url|quote)\].*?\[/\1\]`. +The full pattern: `pattern:\[(b|url|quote)\].*?\[/\1]`. In action: ```js run -let regexp = /\[(b|url|quote)\].*?\[\/\1\]/gs; +let regexp = /\[(b|url|quote)].*?\[\/\1]/gs; let str = ` [b]hello![/b] @@ -20,4 +20,4 @@ let str = ` alert( str.match(regexp) ); // [b]hello![/b],[quote][url]http://google.com[/url][/quote] ``` -Please note that besides escaping `pattern:[` and `pattern:]`, we had to escape a slash for the closing tag `pattern:[\/\1]`, because normally the slash closes the pattern. +Please note that besides escaping `pattern:[`, we had to escape a slash for the closing tag `pattern:[\/\1]`, because normally the slash closes the pattern.