I have this string:
String a = "$$bar$55^$$";
I want remove all symbols. I make regex:
String b = a.replaceAll("(?<=[^[\\p{Alpha}][\\p{Digit}]])", "");
But, I get:
$$bar$55^$$
But I want to get this string:
bar55
What am I doing wrong? How can I filter out all characters except letters and numbers?
In Oracle it work for me:
select regexp_replace('$$bar$55^$$','[^[:alpha:][:digit:]]*') from dual;
[[:alpha:]]can be translated as\p{Alpha}, not[\\p{Alpha}]. POSIX character classes can only be used inside bracket expressions (Oracle uses a POSIX regex engine), and shorthand character classes in Java regex do not have to be wrapped with[...]individually. Also,[[:alpha:][:digit:]]=[[:alnum:]]. Hence, I suggest\P{Alnum}to match any chars other than alphanumeric. Although you also may use"[^\\p{Alpha}\\p{Digit}]+". No need for the nested character classes and the resulting union.