Can somebody help me with converting a php regex to java regex?
It would be great and I would be appreciate you if you can help me, because I'm not so strong in regex.
$str = preg_replace ( '{(.)\1+}', '$1', $str )
$str = preg_replace ( '{[ \'-_\(\)]}', '', $str )
How I understand preg_replace
function in php is the same as replaceAll
in java?..
So in java code it would be like this.
str = str.replaceAll("{(.)\1+}", "$1");
str = str.replaceAll("{[ \'-_\(\)]}", "");
But this code wont be work because how I know that regex in php is different by java.
Please, somebody help me! Thanks a lot))
update
final result is
str = str.replaceAll("(.)\\1+", "$1");
str = str.replaceAll("[ '-_()]", "");
[ '-_()]
(although in PHP you'd still have to escape the'
, of course). – Martin Büttner Jun 26 '13 at 18:42