- 帖子
- 137
- 积分
- 184
- 技术
- 0
- 捐助
- 0
- 注册时间
- 2017-12-23
|
# group组匹配
匹配 name mable 和 years 时,如何将mable后的逗号除去呢
# 需求
# 1、将 name is mable,im 18 years. 匹配出来
# 2、将 name,mable,years 匹配出来
test = ' My name is mable,im 18 years old.'
result_37 = re.search('My(.*)years.', test)
result_38 = re.search('My(.*)is(.*)im.*18(.*)old', test)
# result_38 = re.search('\wMy(.*)is(.*)im.*18(.*)old', test)
# result_38 = re.search('[a-z]?My(.*)is(.*)im.*18(.*)old', test)
result_39 = result_38.groups()
print(result_39) |
|