简体   繁体   中英

replace   between curly brackets

I am using liquid inside html editor.

I have issue when I do copy paste or different cases I have issue.

 var str = "{% if user.firstName = 'joe' || user.firstName = 'ben' %}"; console.log(str.replace(/(\\{)\\s*(\\S+)\\s*(?=})/img, "$1$2")); 

It should output:

{% if user.firstName = 'joe' || user.firstName = 'ben' %}

I've tried : str.replace(/(\\{)\\s*(\\S+)\\s*(?=})/img, "$1$2");

Regex to replace non breaking spaces  

var r = new RegExp('( )','g');
var s = "{% if user.firstName = 'joe' || user.firstName = 'ben' %}"
console.log(s.replace(r,''));
// {% if user.firstName = 'joe' || user.firstName = 'ben' %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM