-5

If I want to search for a newline in a text using Java, should my regex be "\n" or "\\n", or will either work?

Ypnypn
  • 933
  • 1
  • 8
  • 21

1 Answers1

1

You aren't matching a backslahs (\) and an n, you're matching a newline character (represented as \n). There's no need to escape the backslash:

Pattern p = Pattern.compile(".*\n.*");
Mureinik
  • 297,002
  • 52
  • 306
  • 350