Python re Regular Expression instance code, pythonre Regular Expression

Source: Internet
Author: User

Python re Regular Expression instance code, pythonre Regular Expression

This article focuses on the reregex expressions of python. The details are as follows.

Concept: Regular Expressions (generic formulas) are expressions used to express a set of strings in a concise manner. The advantage is conciseness.

Application: string matching.

Instance code:

CODEC = 'utf-8' # encoding: UTF-8 import re p = re. compile ("AB") str = "abfffa" # match must match the first letter if p. match (str): print p. match (str ). group () # match must match the first letter. group () prints matching letters out print re. match ('a + B ', 'abvvaabaaab '). group () # differs from match to match the print re letter at any position. search ('a + B ', 'vvvaabaaab '). group () # print re. findall ('a + B ', 'vabmaabnaaab') print re. split (':', 'str1: str2: str3') # The regular expression print ('str1: str2: str3') cannot be matched '). split (':') # separates strings in the form of a + B. It can match the regular expression print re. split ('a + B ', 'vabmaabnaaab ')

Print Information

AB aab ['AB', 'aab', 'aaab'] ['str1', 'str2', 'str3'] ['str1', 'str2 ', 'str3'] ['V', 'M', 'n', '']

Summary

The above is all the content of the python re Regular Expression instance code in this article, I hope to help you. If you are interested, you can continue to refer to other related topics on this site. If you have any shortcomings, please leave a message. Thank you for your support!

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.