"Go" about the use of the split method of the RE module in Python

Source: Internet
Author: User

Note: Recently in the study of text processing, need to use the regular cutting text, so received this article, very useful, thank the original author.

Original site: http://blog.sciencenet.cn/blog-314114-775285.html

About the use of the split method in the RE module in Python
has been read 3,094 times 2014-3-12 11:30 | System Category: Scientific notes

Today, when writing a small code, you need to use the Re.split () method, in the process of using the discovery of a previously unknown new usage, found that the usage is quite practical, it is recorded:

>>> m = re.split (' \d+ ', ' dkjj23jjjj44 ')

>>>m

[' Dkjj ', ' jjjj ', ']

>>> m = Re.split (' (\d+) ', ' dkjj23jjjj44 ') #匹配部分加上 ()

>>>m

[' Dkjj ', ' All ', ' jjjj ', ' 44 ', ']

>>> m = re.split (' \d+ ', ' dkjj23jjjj44as ') #匹配部分加上了 ()

>>>m

[' Dkjj ', ' jjjj ', ' as ']

>>> m = Re.split (' (\d+) ', ' dkjj23jjjj44as ')

>>>m

[' Dkjj ', ' All ', ' jjjj ', ' a ', ' as ']

After the matching section plus () The result is different, no () does not retain the matching items, but there is () can retain the matching items, this in some need to retain the matching part of the use process is very important.

"Go" about the use of the split method of the RE module in Python

Related Article

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.