Python RE module application example _python

Source: Internet
Author: User

This example describes Python's re module application. is a very important application technique. Share to everyone for your reference.

The specific methods are as follows:

Import Re # match_object = Re.match (' foo ', ' foo ') if Match_object is not none:print type (match_object) print mat Ch_object.group () # match_object = Re.match (' foo ', ' FOOABV ') if Match_object not None:print match_object.group (  
#match从头开始匹配 match_object = re.match (' foo ', ' AFOOABV ') if Match_object is not none:print match_object.group () Else:print ' not match ' #利用面向对象的特点, one row completes the print Re.match (' Love ', ' lovesomebody is a happy thing '). Group () #与mat The difference between CH: match starts from scratch, search is lookup 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 isn't None:print "|...|" + match_object.group () #会匹配成功 else:print ' not match ' BT = ' Bat|bit|bot ' match_obj ECT = Re.search (BT, ' AABATSDF ') if Match_object is not None:print "|search|" + match_object.group () #会匹配成功, if you use match With success Else:print ' not Match 

 

This article example test environment for Python2.7.6

The results of the operation are as follows:

<type ' _sre. Sre_match ' >
foo foo not
Match love
foo
|...| Bat
|search|bat

I hope this article will help you with your Python programming.

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.