For the use of the re module split method in python, pythonsplit

Source: Internet
Author: User

[Switch] for the use of the re module split method in python, pythonsplit

Note: Recently, we have been studying text processing and need to use regular cut text. Therefore, this article is very useful. Thank you for choosing the original author.

Site: http://blog.sciencenet.cn/blog-314114-775285.html

Use of the re module split method in python
3094 times read: | system category: scientific research notes

We need to use re when writing a small piece of code today. the split () method discovers a new usage that was previously unknown during use. If it finds that this usage is quite practical, record it:

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

>>> M

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

>>> M = re. split ('(\ d +)', 'dkjj23jjjj44') # Add () to the matching part ()

>>> M

['Dkjj ', '23', 'jjjj', '44', '']

>>> M = re. split ('\ d +', 'dkjj23jjjj44as ') # Add () to the matching part ()

>>> M

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

>>> M = re. split ('(\ d +)', 'dkjj23jjjjj44as ')

>>> M

['Dkjj ', '23', 'jjjj', '44', 'as']

The results after () is added to the matching part are different. If () is not used, the matched items are not retained, but if () is used, the matched items are retained, this is very important in the use of some matching parts that need to be retained.

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.