Reputation: 9295
is there any way to do the next lines of code more elegant in javascript? Basically I am trying to replace any occurrence of {{
or }}
with empty string. Here is what I use now:
tmp = "{{ some_text }}"
tmp = tmp.replace(/{{/g , "");
tmp = tmp.replace(/}}/g , "");
tmp = tmp.trim();
Thanks!
Upvotes: 0
Views: 59
Reputation: 76646
This one handles the whitespace as well:
tmp = tmp.replace(/{{\s*|\s*}}/g, '')
"some_text"
Upvotes: 2
Reputation: 318342
You can use OR in the regex
tmp = "{{ some_text }}";
tmp = (tmp.replace(/{{|}}/g, "")).trim();
Upvotes: 2
Reputation: 174836
Just try the below,
tmp = tmp.replace(/{{|}}/g , "");
tmp = tmp.trim();
In regex |
symbol means logical OR operator.
Upvotes: 1