Matching Multiple rows ^ and $

Source: Internet
Author: User

 ^Match the starting position of a row or string;

In enhancement mode, ^ matches the position after each line break.

 

NOTE: If there are multiple lines of text, for example:

First linesecond line

The actual content is:

First line [Cr] [LF] Second line

[Cr] carriage return
[LF] line feed

Therefore, in the enhancement mode,^It can match the starting position of each line of text. The reason for this explanation is that it conforms to our eye habits.

Note:$This can cause us a headache.

 

$Matches the end position of a string/line, but in enhancement mode,$It can match the linefeed inside the string.

Instance:

Text/string:ABC

Regular Expression:^ ABC $

Matching result:ABC

 

String:

123456

Regular Expression:(? M) ^ \ D {3} $

Matching result:456

Note:(? M)Enable the enhancement mode.

 

Why does the first row 123 fail to match?

Because$The carriage return cannot match.

123 [Cr] [LF] 456

Think about why 123 cannot be matched, and why 456 can be matched.

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.