joplin-notes/joplin notion extension/Web Development/Javascript/regular expressions.md
2026-11-04 00:33:23 +05:30

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/