ReGex - Python - 从单词到句子中的第一个点
ReGex - Python - From word till the first dot in a sentencce
text = "hello there. I would like to capture from this point till the end"
capture= re.findall(r'(point).$',text)
print (capture)
有人能告诉我我做错了什么吗?谢谢。
假设您想捕获某个单词之后的所有内容,直到下一个点或字符串的末尾:
point(.*?)(?:\.|$)
这里,(.*?)
是一个捕获组,在non-greedy fashion中匹配任何字符0次或更多次。 (?:\.|$)
是一个非捕获组,匹配字符串的点或结尾。
演示:
>>> re.findall(r'point(.*?)(?:\.|$)', "hello there. I would like to capture from this point till the end")
[' till the end']
>>> re.findall(r'point(.*?)(?:\.|$)', "hello there. I would like to capture from this point till the end of the sentence. And now there is something else here.")
[' till the end of the sentence']
text = "hello there. I would like to capture from this point till the end"
capture= re.findall(r'(point).$',text)
print (capture)
有人能告诉我我做错了什么吗?谢谢。
假设您想捕获某个单词之后的所有内容,直到下一个点或字符串的末尾:
point(.*?)(?:\.|$)
这里,(.*?)
是一个捕获组,在non-greedy fashion中匹配任何字符0次或更多次。 (?:\.|$)
是一个非捕获组,匹配字符串的点或结尾。
演示:
>>> re.findall(r'point(.*?)(?:\.|$)', "hello there. I would like to capture from this point till the end")
[' till the end']
>>> re.findall(r'point(.*?)(?:\.|$)', "hello there. I would like to capture from this point till the end of the sentence. And now there is something else here.")
[' till the end of the sentence']