在Python中提取第一个空格后的子字符串

在Python中提取第一个空格后的子字符串,python,regex,Python,Regex,我需要正则表达式或Python中的帮助来从一组字符串中提取子字符串。字符串由字母数字组成。我只想要在第一个空格之后开始,在最后一个空格之前结束的子字符串,如下面给出的示例 Example 1: A:01 What is the date of the election ? BK:02 How long is the river Nile ? Results: What is the date of the election How long is the river Nile 当我

我需要正则表达式或Python中的帮助来从一组字符串中提取子字符串。字符串由字母数字组成。我只想要在第一个空格之后开始,在最后一个空格之前结束的子字符串,如下面给出的示例

Example 1:

A:01 What is the date of the election ?
BK:02 How long is the river Nile ?    

Results:
What is the date of the election
How long is the river Nile
当我这么做的时候,有没有一种简单的方法可以在某个字符之前或之后提取字符串?例如,我想从示例2中给出的字符串中提取日期

Example 2: 

Date:30/4/2013
Day:Tuesday

Results:
30/4/2013 
Tuesday

我确实读过关于regex的书,但它对我来说很陌生。谢谢。

如果您只需要正则表达式,那么就没有必要深入研究正则表达式;您可以使用
str.partition

s = "A:01 What is the date of the election ?"
before,sep,after = s.partition(' ') # could be, eg, a ':' instead
如果您只需要最后一部分,可以使用
\u
作为“不在乎”的占位符:

_,_,theReallyAwesomeDay = s.partition(':')

我建议使用
split

>>> s="A:01 What is the date of the election ?"
>>> " ".join(s.split()[1:-1])
'What is the date of the election'
>>> s="BK:02 How long is the river Nile ?"
>>> " ".join(s.split()[1:-1])
'How long is the river Nile'
>>> s="Date:30/4/2013"
>>> s.split(":")[1:][0]
'30/4/2013'
>>> s="Day:Tuesday"
>>> s.split(":")[1:][0]
'Tuesday'

不要使用
\uu
,只需使用
ThereallyWesomeday=s.partition(':')[2]
@gnibler-我认为
\u
更清晰,特别是因为通常使用
开始、\uu,结束=s.partition(':')
(因此,只在结束时使用相同的形式是有意义的)使用
作为
gettext
的别名也很常见,谢谢!您的代码完全符合我的需要,无需使用正则表达式。我在尝试regex,但运气不好。
>>> s="A:01 What is the date of the election ?"
>>> s.split(" ", 1)[1].rsplit(" ", 1)[0]
'What is the date of the election'
>>>