Python regular expression re-module uses

Source: Internet
Author: User

The first regular expression of Python

R ' Imooc ' Pattern Match result

In [2]:ImportReIn [3]: PA = re.compile (r'IMOOC')#the compile method of re generates pattern objectIn [4]: Type (PA) out[4]: _sre. Sre_patternin [5]: Pa.pa.findall pa.fullmatch pa.match pa.search pa.subnpa.finditer pa.groupindex Pa.pattern Pa.split pa.flags pa.groups pa.scanner pa.sub in [8]: str ='Imooc python'In [9]: Pa.match (str)#Match method of the Pattern object matches the stringOUT[9]: <_sre. Sre_match object; Span= (0, 5), match='IMOOC'>In []: MA =Pa.match (str) in [11]: MA. Ma.end ma.group ma.lastgroup ma.re ma.start ma.endpos ma.groupdict ma.lastindex ma.regs ma.string ma.expand ma.groups MA.P Os Ma.span in [11]: Ma.group () out[11]:'IMOOC' #returns the string that matches toIn [15]: Ma.span () out[15]: (0, 5)#returns the matched string subscript index

In [1]:ImportReIn [2]: PA = re.compile (r'IMOOC', Re. I)#Ignore letter CaseIn [3]: paout[3]: Re.compile (r'IMOOC', Re. ignorecase|Re. UNICODE) in [4]: ma = Pa.match ('Imooc python') in [5]: Ma.group () out[4]['IMOOC'In [6]: Ma = Pa.match ('Imooc python') in [7]: Ma.group () out[7]:'IMOOC'In [8]: ma = Pa.match ('Imooc python') in [9]: Ma.group () out[9]:'IMOOC'In [10]: ma.groups () out[10]: () in [ALL]: PA = re.compile (r'(IMOOC)', Re. I) in [[]: Ma = Pa.match ('IMOOC') in [13]: Ma.group () out[13]:'IMOOC'In [14]: ma.groups () out[14]: ('IMOOC',)#return as a groupIn [[]: Ma = Re.match (r'IMOOC','Imooc python')#compile and match can be mergedIn [16]: Ma.group () out[16]:'IMOOC'

Python regular expression re-module uses

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.