This commit is contained in:
nm1 2026-11-04 00:33:23 +05:30
commit 74ae93a96e

View file

@ -0,0 +1,19 @@
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/`