return str.replace(/[\(\)\.\-\s,]/g, "")
views:
64answers:
3
+5
A:
return preg_replace('/[\(\)\.\-\s,]/', '', $str);
For what it's worth, most of those backslashes are unnecessary (in either language). Parentheses and dots do not need to be escaped inside of character classes. You could simplify that to this if you wish:
return preg_replace('/[().\-\s,]/', '', $str);
John Kugelman
2010-09-22 20:43:36
You can move the `-` to the end: `/[().\s,-]/`
Felix Kling
2010-09-22 20:47:13
@Felix Yes, you're right, although that toes the line between "clean" and "a bit too clever".
John Kugelman
2010-09-22 21:04:10
+1
A:
$string = preg_replace('/[\(\)\.\-\s,]/','',$string);
Simple as that.
Note: The modifier g
in php does not exists
RobertPitt
2010-09-22 20:43:49
The modifier `g` does not exist in PHP PCRE: http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php
Felix Kling
2010-09-22 20:46:00
+2
A:
return preg_replace('/[().\s,-]/', '', $str);
You don't need to escape all those characters in a character class (neither in JavaScript nor PHP).
Tim Pietzcker
2010-09-22 20:45:35