Python: Regular Expressions

Source: Internet
Author: User
Tags alphabetic character

Regular expressions are strings of characters and special symbols that are powerful tools for working with strings and can support multiple programming languages, so regular expressions are independent and useful, and worth learning, compared to various programming languages.

In the final analysis, a regular expression can match a set of strings with similar characteristics in a pattern.

symbols Description Example
. Matches any character (except line breaks) A.B represents AB between a character a2b, a5b, Alb, a*b
^ Match the start of a string ^from represents any string starting with a from
$ Match the end of a string bi/li$ represents any string ending with bi/li
* Matches the preceding occurrence of the regular expression 0 or more times
+ Matches the preceding occurrence of a regular expression one or more times \d+ represents a number with at least one digit
Matches the previous occurrence of the regular expression 0 or one time Ab? Denotes A or AB
N Matches the preceding occurrence of the regular expression n times \D{3} represents three consecutive digits, such as 123,596
{M,n} Matches a regular expression that repeats m times to N times
[...] Match any one of the characters that appear in the character set [23] is 2 or 3,[cr][23] means C2 or C3 or R2 or R3
[X-y] Match any character from character X to Y [A-z] denotes a character between A and Z
[^xy] does not match any one of the characters that appear in this character set [^ABC] denotes characters other than a,b,c
\d Match (0~9) any number Any number, 0 to 9
\w Match any numeric alphabetic character Any alphanumeric character: *,/,-,a,8
\s Match any whitespace character
\b Match the boundaries of a word \bthe represents any string starting with "the", \bthe\b means "the"
\c Match Special characters individually
\a (\z) Start of Match string (end) Similar to ^ and $, the original to prevent the international keyboard does not have these two characters and stipulated

0? [1-9]
Represents 01 to 09 or 1 to 9

[0-9] {15,16}
Represents a 15 or 16 digit number, for example: credit card number

\d{3}-\d{3}-\d (4)
Indicates for example 800-555-1212

\[email protected]\w+\.com
Represents the e-mail address format, '. ' The preceding ' \ ' stands for inverted literal characters such as [email protected]

\d+ (\.\d*)?
Represents a simple floating-point number, that is, any decimal digit followed by an optional decimal point and then followed by 0 or more decimal digits. For example: "0.004," "2", "75.", etc.

(Mr?s?)? [A-z] [A-z]* [a-za-z-]+
Indicates first name and last name, the limit of the first letter, the other letter (if present) lowercase, there is an optional title before the full name ("Mr.," "" Mrs, "" Ms., "or" M., "), the last name has no limitations, allowing multiple words, dashes, uppercase letters.

Original link: http://www.jianshu.com/p/cf767826d630

Python: Regular Expressions

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.