minor fixes

This commit is contained in:
Ilya Kantor 2021-11-01 20:57:19 +03:00
parent 6989312841
commit cc18823108

View file

@ -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.