java regex escape sequences -
i wondering regex in java , stumbled upon use of backslashes. instance, if wanted occurences of words "this regex" in text, this:
pattern.compile("this regex");
nonetheless, this:
pattern.compile("this\\sregex");
my question is: difference between 2 of them? , why have type backslash twice, mean, why isn't \s escape sequence in java? in advance!
\s
means whitespace character, including tab, line feed , carriage return.- java string literals use
\
escape special characters. put character\
in string literal, need write"\\"
. regex patterns use\
escape character, , way put string literal use two, because goes through 2 separate escaping processes. if read regex pattern plain text file example, won't need double escaping.
Comments
Post a Comment