I want to remove character from a string ex: [\"lorem ipsum\"]
, i want like lorem ipsum
without this characters [\" \"]
.
how i can do this in javascript
or PHP
?
I want to remove character from a string ex: [\"lorem ipsum\"]
, i want like lorem ipsum
without this characters [\" \"]
.
how i can do this in javascript
or PHP
?
In javascript
var str = "[\"lorem ipsum\"]";
alert(str.replace(/[^a-zA-Z ]/g, ""));
And in PHP
$string = "[\"lorem ipsum\"]";
$result = preg_replace('/[^A-Za-z0-9\-]/', ' ', $string);
echo $result;
JavaScript
If you want to remove this specific combination [\" \"]
just use the replace
function:
mystring = mystring.replace('[\"','');
mystring = mystring.replace('\"]','');
If you want to remove all non-alphanumeric chars:
The following is the/a correct regex to strip non-alphanumeric chars from an input string:
mystring = mystring.replace(/\W/g, '')
Note that \W
is the equivalent of [^0-9a-zA-Z_]
- it includes the underscore character. To also remove underscores use e.g.:
mystring = mystring.replace(/[^0-9a-z]/gi, '')