Common Regular Expressions

Source: Internet
Author: User
Tags alphabetic character

In the process of developing automated test scripts, it is a good solution to use regular expression fuzzy matching to solve the recognition and validation of property-like objects, and there are too many regular expression categories to summarize the most commonly used categories of work:

Metacharacters

Describe
\ Marks the next character as a special character, or a literal character, or a backward reference, or an octal escape. For example, "\\n" matches \ n. "\ n" matches the line break. The sequence "\ \" matches "\" and "\ (" Matches "(".
. Point Matches any single character except for "\ r \ n". To match any character that includes "\ r \ n", use a pattern like "[\s\s]".
* Matches the preceding sub-expression 0 or more times (greater than or equal to 0 times). For example, zo* can match "Z", "Zo" and "Zoo". * Equivalent to {0,}.
+ Matches the preceding subexpression one or more times (greater than or equal to 1 times). For example, "zo+" can Match "Zo" and "Zoo", but not "Z". + equivalent to {1,}.
^ Matches the starting position of the input string. If the multiline property of the RegExp object is set, ^ also matches the position after "\ n" or "\ r".

[A-z]

[A-z]

The character range. Matches any character within the specified range. For example, "[A-z]" can match any lowercase alphabetic character in the range "a" to "Z". Note: The range of characters can be represented only if the hyphen is inside a character group and appears between two characters; If the beginning of a character group, it can only represent the hyphen itself

[^a-z]

[^a-z]

A negative character range. Matches any character that is not in the specified range. For example, "[^a-z]" can match any character that is not in the range "a" to "Z".

[0-9]

The number range. Matches any number in the specified range. For example, "[0-9]" can match any number in the range 0 to 9.
[^0-9] Negative numeric range. Matches any character that is not in the specified range. For example, "[^0-9]" can match any character that is not in the range 0 to 9.

\d

Matches a numeric character. equivalent to [0-9].

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}

Both 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.

\D{4}

Match 4 numeric characters

X|y

Match x or Y. For example, "Z|food" can match "Z" or "food". "(z|f) Ood" matches "Zood" or "food".

[XYZ]

The character set is combined. Matches any one of the characters contained. For example, "[ABC]" can Match "a" in "plain".

[^XYZ]

Negative character set. Matches any character that is not contained. For example, "[^ABC]" can match "Plin" in "plain".

Common Regular Expressions

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.