Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to combine regular expressions in javascript?

This might be easy for those who play with regular expressions.

str = "Here is 'sample' test";
str = str .replace(new RegExp('"', 'g'), '');
str = str .replace(new RegExp("'", 'g'), '');

How to combine 2nd and 3rd line, I want to combine regular expressions new RegExp('"', 'g') and new RegExp("'", 'g') into one regular expression, this will make it in one line. Thanks in advance.

like image 211
Riz Avatar asked Dec 16 '22 20:12

Riz


1 Answers

str = str.replace(/"|'/g, '')
like image 198
Andrew Avatar answered Jan 05 '23 02:01

Andrew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!