-4
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

can anyone please explain this code... i'm still confusing about this code and how this code works while compiling

Tomer Shetah
  • 8,413
  • 7
  • 27
  • 35
  • 1
    Which part don't you understand, the skip or the regular expression? Btw. for both there is good documentation available. – Henry Aug 25 '20 at 05:50

3 Answers3

1
  scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

You can read all the details of predefined character classes:

https://docs.oracle.com/javase/10/docs/api/java/util/regex/Pattern.html

Look for horizontal white space and linebreak matcher.

Arvind Kumar Avinash
  • 71,965
  • 6
  • 74
  • 110
huntgang99
  • 61
  • 3
0

This code tells scanner to skip unwanted characters in the input ignoring delimiters.

In this case, a set of characters related to new-line handling are skipped:

Nowhere Man
  • 19,170
  • 9
  • 17
  • 42
  • 2
    "sets up" scanner might be misunderstood as an ongoing thing. It's not. The code is not "setting up" a condition, it is executing the *skip* right then and there, from the current position of the scanner. – Andreas Aug 25 '20 at 06:17
0

Explanation for the string:

\r\n - a pair of CRLFs like in Windows, or any of the following single characters:

\r - CR (carriage return) MacOS line separator,

\n - LF (line feed) Unix line separator,

\u2028 - Unicode line separator,

\u2029 - Unicode paragraph separator,

\u0085 - Unicode next line.

Arn
  • 1,898
  • 12
  • 26