Regular Expressions (ii)

Source: Internet
Author: User

\b: A meta-character that represents the beginning or end of a character, that is, the word's dividing point. Although English words are usually delimited by spaces, punctuation marks, or line breaks, \b does not match any of these word-delimited characters, it only matches one position.

.: metacharacters, matches any character except newline characters

*: meta-character, but is not a match character, but instead represents * the preceding character can match 0 or more

+: metacharacters, which represent + preceding characters can match one or more

?: Match 0 or one time

\d: meta-characters, matching one digit

-: Match itself, not meta-character

{4} indicates that {} must match exactly 4 times before {}

{5-12} matches 5 to 12 times

\s: metacharacters, matching any white space characters, including spaces, tabs, line breaks, Chinese full-width spaces, etc.

\w: meta-characters, matching letters, numbers, underscores or kanji (one is to see what your system is, the Chinese system is to match the Chinese characters of the second is to see your application environment, if it is in a C # program, can match the Chinese characters, in JavaScript or validation control, is not to match the Chinese characters of the other \ D,\s, too)

^: Match the start of a string

$: Matches the end of a string

\: Used to match meta characters, such as/. /* etc.

[]: represents one of the brackets in the match, [Abcd],a,b,c or D

(exp): grouping, capturing text into an automatically named group

(?‘ Name ' exp ' or (? <name>exp) capture the text into a group named name

(?: EXP) does not capture content and does not assign group numbers

(? =exp) matches the position prior to exp, and the back of its occurrence position can match exp

(? <=exp) matches the position after exp, the front of its own occurrence position can match exp

(?! EXP) asserts that the back of this position does not match exp (using antisense may be an error)

(? <!exp)

(?#...) or # comment

Qualifiers, grouping (), post-application (after grouping there are labels from left to right, first opening parenthesis label 1, second label 2: using/To refer to regular expressions in grouping), 0 wide assertion, greedy match and lazy matching

Table 1. the common metacharacters

Code

Description

.

Match any character other than line break

\w

Match letters or numbers or underscores or kanji

\s

Match any of the whitespace characters

\d

Match numbers

\b

Match the beginning or end of a word

^

Match the start of a string

$

Match the end of a string

{n,}

tr> TD valign= "Center" width= "288" >

Table 2. common qualifiers

Code/syntax

Description

*

Repeat 0 or more times

+

Repeat one or more times

?

Repeat 0 or one time

{n}

Repeat n times

Repeat n or more times

{n,m}

Repeat N to M times

Table 3. commonly used anti-semantic code

Code/syntax

Description

\w

Match any characters that are not letters, numbers, underscores, kanji

\s

Match any character that is not a whitespace character

\d

Match any non-numeric character

\b

Match a position that is not the beginning or end of a word

[^x]

Matches any character except X

[^aeiou]

Matches any character except for the letters AEIOU

Table 4. Common grouping Syntax

Classification

Code/syntax

Description

Capture

(exp)

Match exp, and capture text into an automatically named group

(? <name>exp)

Match exp, and capture the text to a group named name, or you can write (? ') Name ' exp ')

(?: EXP)

Matches exp, does not capture matching text, and does not assign group numbers to this group

0 Wide Assertion

(? =exp)

Match the position of the exp front

(? <=exp)

Match the position after exp

(?! Exp

Match the position followed by the exp.

(? <!exp)

Match a location that is not previously exp

Comments

(? #comment)

This type of grouping does not have any effect on the processing of regular expressions, and is used to provide comments for people to read

Table 5. Lazy Qualifier

Code/syntax

Description

*?

Repeat any number of times, but repeat as little as possible

+?

Repeat 1 or more times, but repeat as little as possible

??

Repeat 0 or 1 times, but repeat as little as possible

{n,m}?

Repeat N to M times, but repeat as little as possible

{N,}?

Repeat more than n times, but repeat as little as possible

Table 7. syntax not discussed in detail

Code/syntax

Description

\a

Alarm character (the effect of printing it is the computer beeps)

\b

is usually the word dividing position, but if the delegate backspace is used in the character class

\ t

tab, tab

\ r

Enter

\v

Vertical tab

\f

Page break

\ n

Line break

\e

Escape

\0nn

The octal code in ASCII code is an nn character

\xnn

The hexadecimal code in the ASCII code is an nn character

\unnnn

Characters with hexadecimal code nnnn in Unicode code

\cn

ASCII control characters. For example, \CC represents CTRL + C

\a

The beginning of the string (similar to ^, but not affected by the processing of multiline options)

\z

End of string or end of line (not affected by multi-line processing options)

\z

End of string (similar to $, but not affected by the processing of multiline options)

\g

The beginning of the current search

\p{name}

A character class named name in Unicode, such as \p{isgreek}

(? >exp)

Greedy sub-expression

(? <x>-<y>exp)

Balance Group

(? im-nsx:exp)

Change processing options in the sub-expression exp

(? im-nsx)

Change the processing options for the sections that follow the expression

(? (exp) yes|no)

DECLARE exp as a 0-wide forward assertion, if it matches in this position, use Yes as the expression for this group, otherwise use no

(? (exp) Yes)

Ditto, just use an empty expression as no

(? (name) yes|no)

If the group named name captures the content, use Yes as the expression;

(? (name) Yes)

Ditto, just use an empty expression as no

Regular Expressions (ii)

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.