Regular Expression Reguler Expression (with Python re) __ regular expressions

Source: Internet
Author: User

When you need to match a string with a regular expression in Python, you can use a module, the name re
' Match ' scan a string start from the very left,if it not match,it 'll break

#coding =utf-8
# importing RE module import re
# using the match method for matching operations result
 = Re.match (regular expression, string to match)
# If the previous step matches the data, you can use the group method to extract the data
result.group ()

Match Character

S=r ' \w{4,20}@ (163|126|qq) \.com '

Search

This function would search in the whole String,and

FindAll
This function would search all the string satisfy the requirement.

Search vs FindAll

Sub
Substitute the string required
1.simple Replace

2,use function to replace the specified string

Split

greed and non-greed
In Python, the quantity word is greedy by default (in a few languages it may also be the default and not greedy), always trying to match as many characters as possible;
Non-greed is the opposite, always trying to match as few characters as possible.

After "*", "?", "+", "{m,n}" plus. , so that greed becomes not greedy.

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.