Python re module application instance and pythonre application instance
This article describes the re module application of python. Is a very important application technique. Share it with you for your reference.
The specific method is as follows:
Import re # match_object = re. match ('foo', 'foo') if match_object is not None: print type (match_object) print match_object.group () # match_object = re. match ('foo', 'fooabv') if match_object is not None: print match_object.group () # match matches match_object = re from the beginning. match ('foo', 'afooabv') if match_object is not None: print match_object.group () else: print 'not Match' # print re in one row based on object-oriented features. match ('love', 'loveomebodyis a happy thing '). group () # difference from match: match matches from the beginning, search is to find match_object = re. search ('foo', 'afooabv') if match_object is not None: print match_object.group () else: print 'not Match' # | use bt = 'bat | bit | bot 'match_object = re. match (bt, 'batsdf ') if match_object is not None: print "|... | "+ match_object.group () # The match will be successful. else: print not match 'bt = 'bat | bit | bot 'match_object = re. search (bt, 'aabatsdf ') if match_object is not None: print "| search |" + match_object.group () # The match is successful. if match is used, the match will not succeed. else: print 'not Match'
The test environment of this example is Python2.7.6.
The running result is as follows:
<type '_sre.SRE_Match'>foofoonot matchlovefoo|...|bat|search|bat
I hope this article will help you with Python programming.
In the re module of python, how does one use variables to replace the strings to be matched?
Try this: XH = raw_input ("Enter your phone model:") XH_re = re. compile (XH + '.*? $ (\ D {1, 4}) </em> ', re. DOTALL)
What if people always cough?
Take medicine! Or go to the hospital to check the lung