Hallo,
String text2 = text1.replaceAll("blub", "[\w\d]+"); // <--- wieviele Backslashes
Wieviele Backslashes brauche ich nun bei text1.replaceAll damit es dann in text0.replaceAll als regulärer Ausdruck verwendet wird und warum?
Beantwortet folgendes deine Frage schon?
"Backslashes within string literals in Java source code are interpreted as required by the Java Language Specification as either Unicode escapes or other character escapes. It is therefore necessary to double backslashes in string literals that represent regular expressions to protect them from interpretation by the Java bytecode compiler. The string literal "\b", for example, matches a single backspace character when interpreted as a regular expression, while "\b" matches a word boundary. The string literal "(hello)" is illegal and leads to a compile-time error; in order to match the string (hello) the string literal "\(hello\)" must be used."
Dieser Absatz entstammt aus der Klassendokumentation von java.util.regex.Pattern.
Gruß
Slyh