-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
  • 943
  • 1
  • 8
  • 20

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
  • 277,661
  • 50
  • 283
  • 320