如何使用逗号在特定字符串和maxsplit = 1之前使用python regex进行拆分? 例如,这是一个字符串: 专业:"美容医学,肿瘤学" ,职业:"医师(MD,DO,Resident)" 我需要在#34; Profession"。
之前将此字符串拆分为逗号(,)答案 0 :(得分:1)
这样的事情?
#!/usr/bin/python2
# -*- coding: utf-8 -*-
import re
txt = 'Speciality: "Aesthetic Medicine, Oncology" , Profession: "Physician (MD, DO, Resident)"'
a = re.match('^(.*?),\s+(Profession:)(.*?)$', txt)
if(a):
# print a.group(0)
first = a.group(1)
second = a.group(2)+a.group(3)
print first
print second
输出:
Speciality: "Aesthetic Medicine, Oncology"
Profession: "Physician (MD, DO, Resident)"