534 B
534 B
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
// 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/