nonprinting characters, special characters, qualifier instance usages (regular expression character set 2)

Source: Internet
Author: User
Tags printable characters
non-printable characters

Character meaning

\CX matches the control character indicated by X. For example, \cm matches a control-m or carriage return. The value of x must be one of a-Z or a-Z. Otherwise, c is treated as a literal ' C ' character.

\f matches a page break. Equivalent to \x0c and \CL.

\ n matches a line break. Equivalent to \x0a and \CJ.

\ r matches a carriage return character. Equivalent to \x0d and \cm.

\s matches any whitespace character, including spaces, tabs, page breaks, and so on. equivalent to [\f\n\r\t\v].

\s matches any non-whitespace character. equivalent to [^ \f\n\r\t\v].

\ t matches a tab character. Equivalent to \x09 and \ci.

\v matches a vertical tab. Equivalent to \x0b and \ck.

Special characters

The so-called special character, is some special meaning of the character, such as the above said "*.txt" in the *, simply means that the meaning of any string. If you are looking for a file with * in the file name, you need to escape the *, which is preceded by a \. LS \*.txt. The regular expression has the following special characters.

Special Character description

$ matches the end position of the input string. If the Multiline property of the RegExp object is set, then $ also matches ' \ n ' or ' \ R '. To match the $ character itself, use \$.

() to mark the start and end positions of a sub-expression. Sub-expressions can be obtained for later use. To match these characters, use \ (and \).

* matches the preceding subexpression 0 or more times. To match the * character, use \*.

+ matches the preceding subexpression one or more times. to match the + character, use \+.

. Matches any single character except for the newline character \ n. To match, please use \.

[Marks the beginning of a bracket expression. to match [, please use \[.

? Matches the preceding subexpression 0 or one time, or indicates a non-greedy qualifier. to match? characters, use \?.

\ marks the next character as either a special character, or a literal character, or a backward reference, or octal escape character. For example, ' n ' matches the character ' n '. ' \ n ' matches line breaks. The sequence ' \ \ ' matches ' \ ', while ' \ (' then Match ' (".

^ matches the starting position of the input string, unless used in a square bracket expression, at which point it indicates that the character set is not accepted. To match the ^ character itself, use \^.

{The beginning of the tag qualifier expression.} To match {, use \{.

| Indicates a choice between the two items. to match |, please use \|.

The method of constructing a regular expression is the same as the method for creating a mathematical expression. That is, using a variety of meta-characters and operators to combine small expressions together to create larger expressions. A component of a regular expression can be a single character, a character set, a range of characters, a selection between characters, or any combination of all of these components.

Qualifier

Qualifiers are used to specify how many times a given component of a regular expression must appear to satisfy a match. There are 6 types of * or + or? or {n} or {n,} or {n,m}.

The *, +, and? Qualifiers are greedy because they match as many words as possible, but only after they are added with one? You can implement a non-greedy or minimal match.

The qualifiers for a regular expression are:

Character description

* matches the preceding subexpression 0 or more times. For example, zo* can match "z" and "Zoo". * Equivalent to {0,}.

+ matches the preceding subexpression one or more times. For example, ' zo+ ' can match "Zo" and "Zoo", but not "Z". + equivalent to {1,}.

? Matches the preceding subexpression 0 or one time. For example, "Do (es)?" can match "do" in "do" or "does".? Equivalent to {0,1}.

{n} n is a non-negative integer. Matches the determined n times. For example, ' o{2} ' cannot match ' o ' in ' Bob ', but can match two o in ' food '.

{N,} n is a non-negative integer. Match at least n times. For example, ' o{2,} ' cannot match ' o ' in ' Bob ', but can match all o in ' Foooood '. ' O{1,} ' is equivalent to ' o+ '. ' O{0,} ' is equivalent to ' o* '.

{n,m} m and n are non-negative integers, where n <= m. Matches at least n times and matches up to M times. For example, "o{1,3}" will match the first three o in "Fooooood". ' o{0,1} ' is equivalent to ' O? '. Note that there can be no spaces between a comma and two numbers.

Related Article

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.