JSFiddle - React, Tailwind, and code Playground

by Pankaj Kargirwar

JavaScript

function quoteRegex(str) {
   let delimiter = '/';
   //https://locutus.io/php/pcre/preg_quote/
   // \ + * ? [ ^ ] $ ( ) { } = ! < > | : - #
   return str.replace(/\\/g, "\\\\")
 }
 

 let str = ' select * from table';
 let r1 = quoteRegex('^\s+');
 console.log(r1);
 r1 = new RegExp(r1);
 let m = str.match(r1);

 console.log(m)