regex for anything but quoted strings site:stackoverflow.com code example

Example 1: regex for anything but quoted strings site:stackoverflow.com

var rgx = /(\B(".+?")\B|\B('.+?')\B|\B(`.+?`)\B)/g;

var str = `"Lorem ipsum dolor sit amet", consectetur adipisicing elit, "'sed do eiusmod tempor,'" incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, \`quis nostrud\` exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. \`Duis aute irure dolor\` in "reprehenderit in voluptate" velit esse cillum 'dolore eu fugiat nulla' pariatur. `;

var sub = ``;

var res = str.replace(rgx, sub);

console.log(res);

Example 2: regex for anything but quoted strings site:stackoverflow.com

/(\B(".+?")\B|\B('.+?')\B|\B(`.+?`)\B)/g;

Tags:

Misc Example