Merge pull request #886 from overken/patch-2

Update article.md
This commit is contained in:
Ilya Kantor 2019-04-02 08:41:34 +03:00 committed by GitHub
commit 64ffd43ca9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,7 +12,7 @@ For server-side Javascript it may become a vulnerability, and it uses regular ex
So the problem is definitely worth to deal with.
## Introductin
## Introduction
The plan will be like this:
@ -254,7 +254,7 @@ Unfortunately, but both these features are not supported by JavaScript.
### Lookahead to the rescue
We can get forbid backtracking using lookahead.
We can forbid backtracking using lookahead.
The pattern to take as much repetitions as possible without backtracking is: `pattern:(?=(a+))\1`.
@ -274,7 +274,7 @@ Let's fix the regexp for a tag with attributes from the beginning of the chapter
```js run
// regexp to search name=value
let reg = /(\s*\w+=(\w+|"[^"]*")\s*)/
let attrReg = /(\s*\w+=(\w+|"[^"]*")\s*)/
// use new RegExp to nicely insert its source into (?=(a+))\1
let fixedReg = new RegExp(`<\\w+(?=(${attrReg.source}*))\\1>`, 'g');