Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write escape character to string?

Tags:

java

escaping

How to write escape character "\" to string?

like image 400
user488963 Avatar asked Nov 01 '10 15:11

user488963


2 Answers

In a normal string, you use \\

If this is in a regular expression, it needs to be \\\\

The reason RegEx needs four is because both the String parser and RegEx engine support escapes. Therefore, \\\\ is parsed to \\ by the String parser then to a literal \ by the RegEx parser.

like image 63
Powerlord Avatar answered Sep 24 '22 19:09

Powerlord


Escape the escape character: "\\"

like image 28
Starkey Avatar answered Sep 25 '22 19:09

Starkey