19 lines
No EOL
534 B
Markdown
19 lines
No EOL
534 B
Markdown
regular expressions
|
|
|
|
- dot character in regex dont include newline character so use this `[\s\S]` instead of `.`.
|
|
eg: `const questionreg = /\.gpt\s+([\s\S]*)/;`
|
|
- variables in regex
|
|
```js
|
|
// variable == 'REGEX'
|
|
|
|
// to escape special characters like +,.,etc in variable string
|
|
function escapeRegExp(string) {
|
|
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
}
|
|
|
|
const variable = <VALUE>
|
|
|
|
let re = new RegExp(String.raw`\s${variable}\s`, "g");
|
|
```
|
|
- word boundary
|
|
to search by word `/\bword\b/` instead of `/word/` |