Use a regular expression literal instead of the 'RegExp' constructor
时间: 2024-02-25 14:58:09 浏览: 170
Regular Expressions
Sure, using a regular expression literal is generally preferred over using the `RegExp` constructor. Here is an example:
Instead of using:
```
let regex = new RegExp('hello', 'i');
```
You can use a regular expression literal like this:
```
let regex = /hello/i;
```
It's shorter and easier to read.
阅读全文