The match regular expression method

All along, regular expressions are very fear that learning automation interfaces, to the regular, I wanted to give up, Ever since, I almost have no more than a month to continue learning. One day woke up, the sun is just right, spread on the bed of meditation, I can not be in front of me Hom blocking the way forward Yeah, went ahead and turn on the computer, I began to enter the learning state, it took an hour to look over, mentality of flat, accumulated bit by bit, over and over again to practice and stick to it, there will be good results.

Back to the topic, today is sharing method match the regular expression, did not talk much to say, look at the code:

 

Re Import


'' '
regular expression:
the equivalent of a mold, the mold can take to find out all the content in line with
the steps:
1. Create a regular expression
2. The regular expression must be added to r, if some characters have special meaning , the need to add a front \
columns such as: R & lt '\ $ {} balalal'
3.match method can only start from scratch, the matching can not return None, matched to the return match object

'' '
# create a string to be replaced
one_str = '{ "MOBILE_PHONE": "$ {not_existed_tel}", "pwd": "12345678", "type":. 1, "reg_name": "luoxia"}'
# Create a regular expression
one_math = r '{ " MOBILE_PHONE ":" \ not_existed_tel} {$ '
' ''
match for the method of the first regular expression parameter, the second parameter is a string to be queried
can match.group () to get the value of the matching succeeds
' '
Math = re.match (one_math, one_str)
Pass

Guess you like

Origin www.cnblogs.com/irene3235/p/12151671.html