Anybody know, how can i remove signs (&&) with JavaScript on start and on the end of a string?
My string
&& value && value && value &&
or
&& value
or
value &&
I need string like this
value && value && value
or
value
Anybody know, how can i remove signs (&&) with JavaScript on start and on the end of a string?
My string
&& value && value && value &&
or
&& value
or
value &&
I need string like this
value && value && value
or
value
With regexp:
// To remove "&" at the beginning and at the end
"&& value && value && value &&".replace(/^&+|&+$/g, '')
// To remove white spaces
.trim();
Use replace
to replace the &&
and trim
to remove leading/starting white spaces
var string = "&& value && value && value &&";
let replaced = string.replace(/(^&+)|(&+$)/g, "");
console.log(replaced.trim());
Try this it will help you,
var s="&& value && value && value &&";
var a=s.match(/[^&/]+/g).join('&&');
alert(a);