Cheng Planning--python Network programming

Source: Internet
Author: User

Class1 Regular Expressions

#定义

Regular expressions are a logical formula for manipulating strings, and through it we can filter out what we need, such as determining whether a string of numbers is a phone number.

#原理

The string of the regular expression is converted to the Pattern object, then the object is used to process the text and the matching result is obtained, and then the other operations are performed according to the result information.

1 #Coding:utf-82 ImportRe3Pattern = Re.compile (r'Hello')#Convert Regular expressions to pattern objects4Match =pattern.match ('hello,cxy!')5 PrintMatch6 7 ifmatch:8     PrintMatch.group ()9 Else:Ten     Print 'Not match' One  APattern2=re.compile (R'Python') -Match2=pattern2.match ('Hello Cxy') - ifMATCH2: the     PrintMatch2.group () - Else: -     Print 'Not match'

Cheng Planning--python Network 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.