3rd Regular Expression 1

Source: Internet
Author: User

1. Basics of Regular expressions

Regular Expression: A string of characters and metacharacters character, referred to as Re (Regular expression), the main function is text query and string manipulation.

metacharacters (metacharacters): a character used to illustrate the meaning of a character expression, which is used to describe the contents, transformations, and various operational information of a character expression.

Note:A, B, 2 characters belong to ordinary characters , ordinary characters can be understood literally, such as: A can only be understood as the English lowercase letter A, no other hidden meanings. While *, ^, [] and other meta-characters , the shell gives them the meaning beyond the literal meaning, such as: * symbol actually represents the repetition of the preceding character 0 or more times the hidden meaning.

It describes the process of the regular expression used in data stream processing, completes the data filtering, rejects the data that does not satisfy the regular expression, and leaves the data that matches the regular expression.

2. Meta-character set in regular expressions and its significance:

Symbol

Significance

*

0 or more of the ordinary characters before the * character

.

Match any character

^

Matches the beginning of the line, or the character following the non-

$

Match end of Line

[]

Match Character Set fit

\

Escape character, shielding the special meaning of a meta-character

\<\>

Exact match symbol

\{n\}

matches the preceding character n times

\{n,\}

Matches the preceding character at least n times

\{n,m\}

Matches the preceding character appears n times between M times

1 * Symbols

Hel*o: * The normal character in front of the symbol is a l,* character that matches the L character 0 or more times, such as String helo, Hello, Hellllllo can be represented by hel*o

2. Symbols

... 73. Indicates that the first three characters are any character, the 4th and 5th characters are 7 and 3, the last character is any character, such as xcb738, 4j973u can match the above string

3 ^ Symbols

^cloud to match rows that begin with cloud

4 $ symbol

micky$ that matches all rows ending with Micky

^$ indicates a blank line

5 [] Match characters

[A] matches all lowercase letters

[^a-c] matches all characters that are not in the a~c (^ is reversed here)

6 \ Symbol

\.

7 \<\> Symbols

\<the\> exact match words the,them, they, etc. do not match

8 \{\} Series symbols

\{n\}: Matches the preceding character n times, such as Jo\{3\}b match Jooob

\{n,\}: Match the preceding character at least n times, such as Jo\{3,\}b match Jooob, Joooob, Jooooob string

\{n,m\}: Matches the preceding character between N and M times, such as jo\{3,6\}b matching Jooob, Joooooob, and other strings

[A-z] \{5\}: Matches 5 lowercase English letters, such as Hello, house, etc.

3. Expansion of regular expressions

Symbol

Significance

?

Match 0 or 1 of the ordinary characters before it

+

Match 1 or more of the ordinary characters before it

()

Represents a character set or used in expr

|

Represents "or" meaning, matching a set of optional characters

1? Symbol

JO? b matches the O character 0 or 1 times, i.e. Joob,job

2 + Symbols

S+eu matches S1 times or any time, such as Sseu,sssseu. But not seu.

3 () and | characters

R (e|a) d means selecting any one of the character e,a, Red, rad

3. Pass-to-match

1. wildcard (globbing) is the process of extending a non-specific file name that contains wildcards to a batch of specific file names stored on a computer, server, or network.

2. The most commonly used wildcard characters include regular expression metacharacters:?, *, [], {}, ^, and so on, and the wildcard character is not exactly the same as the metacharacters:

    • * The symbol no longer represents the repetition of its preceding character, but rather any character that represents any bit;
    • The character represents any character of one bit;
    • ^ symbol does not represent the beginning of the line in the wildcard, but represents the inverse meaning.

Ls-l *.awk represents the information that lists files that end in. awk;

Ls-l 0?. PEM represents the listing of file information starting with 0, followed by one character, and ending with. Pem;

Ls-l [a-h]*. [^awk]*] lists files that begin with a~h and do not end with. awk.

3rd Regular Expression 1

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.