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.