Например:
- "abc\ndef\n" → "abc \ ndef \ n" (без изменения)
- "abc\ndef" → "abc \ ndef "
Я попробовал это:
| Welcome to JShell -- Version 24
| For an introduction type: /help intro
jshell> UnaryOperator detectMissingNL = s -> s.replaceAll("(?");
detectMissingNL ==> $Lambda/0x00001fe001009218@4b9af9a9
jshell> detectMissingNL.apply("abc\ndef");
$5 ==> "abc\ndef"
jshell> detectMissingNL.apply("abc\ndef\n");
$6 ==> "abc\ndef\n"
Первый вывод $ 5 является правильным, но второй $ 6 , очевидно, неверен. Что происходит?jshell> UnaryOperator detectMissingX = s -> s.replaceAll("(?d)(?");
detectMissingX ==> $Lambda/0x00001fe00100a900@28c97a5
jshell> detectMissingX.apply("abcXdefX");
$14 ==> "abcXdefX"
jshell> detectMissingX.apply("abcXdef");
$15 ==> "abcXdef"
Подробнее здесь: https://stackoverflow.com/questions/796 ... tch-not-at