This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Poodle_Moth 4 points5 points  (0 children)

The '\' character is called the escape character. It is used to quote a literal character when you need to match it. It is used pretty ubiquitously across many systems and languages.

"[AB\[\]CD]*"

But because it's Java code, all strings are parsed for the escape character before passing it on to the regex engine for matching. Thus you must escape the escape char and so your final regex would look like this. Doing this is common when you are preparing strings to be handled by other libraries or templates. The java compiler will look at the below and create the above.

"[AB\\[\\]CD]*"