正则-Strip函数
来源:互联网 发布:linux tee 用法 编辑:程序博客网 时间:2024/06/16 15:30
正则-Strip函数
@(正则表达式)[正则,strip]
- 正则-Strip函数
- strip的正则表达式版本
strip()的正则表达式版本
写一个函数,它接受一个字符串,做的事情和strip()字符串方法一样。如果只传入了要去除的字符串,没有其他参数,那么就从该字符串首尾去除空白字符。否则,函数第二个参数指定的字符将从该字符串中去除。
import redef strip(text, chars=None): """去除首尾的字符 :type text: string :type chars: string :rtype: string """ if chars is None: reg = re.compile('^ *| *$') else: reg = re.compile('^[' + chars + ']*|[' + chars + ']*$') return reg.sub('', text)print(strip(' 123456 ')) # 123456print(strip(' 123456')) # 123456print(strip(' 123456')) # 123456print(strip('123456 654321')) # 123456 654321print(strip('123456 654321', '1')) # 23456 65432print(strip('123456 654321', '1234')) # 56 65print(strip('123456 654321', '124')) # 3456 6543
0 0
- 正则-Strip函数
- strip函数
- strip()函数
- strip函数
- strip函数
- strip()函数。
- makefile strip函数
- python strip()函数 介绍
- python strip()函数 介绍
- python strip()函数
- python中的strip函数
- python strip()函数 介绍
- python strip()函数
- Python的strip函数
- python strip()函数
- python strip() split()函数
- python strip()函数
- python strip()函数
- 面试题--给40亿个不重复的,没有排过序,给一个无符号整数,如何判断这个数在这40亿个数中
- 高数错题:2
- 对线性回归、逻辑回归、各种回归的概念学习
- Discuz!教程之后台隔段时间需要重新登录的解决方法
- HZAU 1199: Little Red Riding Hood 01背包
- 正则-Strip函数
- git init 和 git init –bare 的区别
- AlGO153-最小公倍数
- 等价二叉树
- LeetCode OJ 399. Evaluate Division
- XMU 1615 刘备闯三国之三顾茅庐(三) 【欧拉函数+快速幂+欧拉定理】
- Java中堆与栈的区别(仅做个人知识储备)
- Ubuntu-搭建简易Git-Server
- python小程序--实现对文本的汉字统计