Java classic instance: match the line break in the text and wrap the line break in the classic instance

Source: Internet
Author: User

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 ();}}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.