Java classic instance: match the line break in the text and wrap the line break in the classic instance
By default, regular expressions ^ and $ ignore the row Terminator, which only match the beginning and end of the entire input sequence. If activatedMULTILINEMode, then^InStart of inputAndAfter the line terminator (end of the input). In MULTILINE mode, $ onlyBefore the line terminatorOrEnd of the input sequenceMatch.
Import java. util. regex. pattern;/*** Created by Frank * use a regular expression to search for the linefeed */public class NLMatch {public static void main (String [] args) in the text) {String input = "I dream of engines \ nmore engines, all day long"; System. out. println ("INPUT:" + input); System. out. println (); String [] patt = {"engines. more engines "," ines \ nmore "," engines $ "}; for (int I = 0; I <patt. length; I ++) {System. out. println ("PATTERN:" + patt [I]); boolean found; Pattern p1l = Pattern. compile (patt [I]); found = p1l. matcher (input ). find (); System. out. println ("DEFAULT match" + found );//. represents any symbol (dot all), Pattern pml = Pattern. compile (patt [I], Pattern. DOTALL | Pattern. MULTILINE); found = pml. matcher (input ). find (); System. out. println ("Multiline match" + found); System. out. println ();}}}