Python 提取与特定短语关联的数字

Python 提取与特定短语关联的数字,python,regex,nlp,Python,Regex,Nlp,我想在Python中提取组名及其关联的数字 样本输入: 34 patients have admitted in hospital and distributed in Pune group with 20 patients, Mumbai group with 10 patients and Nagpur group with 4 patients. 样本输出: 'Pune group, 20' 'Mumbai group, 10' 'Nagpur group, 4' 你可以试试: \b(

我想在Python中提取组名及其关联的数字

样本输入:

34 patients have admitted in hospital and distributed in Pune group with 20 patients, Mumbai group with 10 patients and Nagpur group with 4 patients.
样本输出:

'Pune group, 20'
'Mumbai group, 10'
'Nagpur group, 4'
你可以试试:

\b(\S+)\s+group\s+with\s+(\d+)\s+patients
在上面的正则表达式中,pune作为组1,患者计数作为组2

示例源():

你可以试试:

\b(\S+)\s+group\s+with\s+(\d+)\s+patients
在上面的正则表达式中,pune作为组1,患者计数作为组2

示例源():


简单-只需将其拆分并提取“group”之前和“with”之后的任何项目,然后加入them@Lucky苏曼,虽然你在这里已经2年多了,但这是你的第一个问题,欢迎来到Stackoverflow。请尽量提供你已经尝试过的东西,以及你在以后的帖子中提到的其他东西。如果你能向我们展示你在这里尝试过的正则表达式,那就更好了。简单地说,只需将其拆分,然后在“group”之前和“with”之后提取任何项,然后加入them@Lucky苏曼,虽然你在这里已经2年多了,但这是你的第一个问题,欢迎来到Stackoverflow。请尽量提供你已经尝试过的东西,以及你在以后的帖子中提到的其他东西。如果你能告诉我们你在这里尝试过什么正则表达式,那就更好了。