Regex escape sequences

when I use escape sequences like \ , \d or \w my compiler states they are not valid. Do I have to import something in order to use them?

The backslash is also the escape character of Java strings.
If you write "A\tB\nC" in Java, the string will be (like in C)

A     B

and is five characters long.

Some programming languages have special raw strings that do not use escape characters. Java does not have this ability.
You have to always escape the escape character to avoid special characters.
For instance, to achieve the RegEx A\nB\d\., you would write


Here is a helpful website to escape Java strings.

1 Like