Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the compile function of Python

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today, I would like to share with you the relevant knowledge points about how to use the compile function of Python. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.

Example

> import re

> pattern = re.compile (r'([a murz] +) ([a murz] +)', re.I) # re.I means ignore case

> m = pattern.match ('Hello World Wide Web')

> print (m) # matches successfully and returns a Match object > m.group (0) # returns the entire substring 'Hello World'

> m.span (0) # returns the index of the entire substring that matches successfully (0,11)

> m.group (1) # returns the first packet matching substring 'Hello'

> m.span (1) # returns the index (0,5) of the first packet matching successful substring

> m.group (2) # returns the second packet matching substring 'World'

> m.span (2) # returns the substring index of the second packet with a successful match (6,11)

> m.groups () # is equivalent to (m.group (1), m.group (2),...) ('Hello',' World')

> m.group (3) # there is no third grouping

Traceback (most recent call last):

File "", line 1, in

IndexError: no such group

These are all the contents of the article "how to use the compile function of Python". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report