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!

  1. \s means whitespace character, including tab, line feed , carriage return.
  2. 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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -