python 正则表达式篇 - split 用法

python 正则表达式篇 - split 用法

代码

#!/usr/bin/env Python3
# -*- coding: utf-8 -*-
# @Software: PyCharm
# @virtualenv:workon
# @contact: contact information
# @Desc:split
__author__ = '未昔/AngelFate'
__date__ = '2019/8/22 19:35'


def re_split():
    """
     split(string[, maxsplit]) | re.split(pattern, string[, maxsplit]):
按照能够匹配的子串将string分割后返回列表。maxsplit用于指定最大分割次数,不指定将全部分割。
        :return:
    """
    import re

    p = re.compile(r'\d+')
    con = 'one1two2three3four4'

    if len(con)>0:
        result = p.split(con)
        result = ','.join(result)
    return result

if __name__ == '__main__':
    print(re_split())

结果

D:\import\python3.7\python.exe "E:/python/Study/小经验/python正则表达式篇 -  match与search的区别.py"
one,two,three,four,

Process finished with exit code 0