Skip to content

Commit

Permalink
no-unsafe-regex: Fix examples (#1764)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Mar 29, 2022
1 parent dffcea8 commit 871ee95
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions docs/rules/no-unsafe-regex.md
Expand Up @@ -10,21 +10,50 @@ Uses [safe-regex](https://github.com/substack/safe-regex) to disallow potentiall

```js
const regex = /^(a?){25}(a){25}$/;
const regex = RegExp('a?'.repeat(26) + 'a'.repeat(26));
```

```js
const regex = /(x+x+)+y/;
```

```js
const regex = /foo|(x+x+)+y/;
```

```js
const regex = /(a+){10}y/;
```

```js
const regex = /(a+){2}y/;
```

```js
const regex = /(.*){1,32000}[bc]/;
```

## Pass

```js
const regex = /\bOakland\b/;
```

```js
const regex = /\b(Oakland|San Francisco)\b/i;
```

```js
const regex = /^\d+1337\d+$/i;
```

```js
const regex = /^\d+(1337|404)\d+$/i;
```

```js
const regex = /^\d+(1337|404)*\d+$/i;
const regex = RegExp('a?'.repeat(25) + 'a'.repeat(25));
```

```js
const regex = new RegExp('a?'.repeat(25) + 'a'.repeat(25));
```

0 comments on commit 871ee95

Please sign in to comment.