Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ReGex-Python-从单词到句子中的第一个点_Regex_Python 2.7_Sentence - Fatal编程技术网

ReGex-Python-从单词到句子中的第一个点

ReGex-Python-从单词到句子中的第一个点,regex,python-2.7,sentence,Regex,Python 2.7,Sentence,有人能告诉我我做错了什么吗?谢谢。假设您要捕获某个单词后的所有内容,直到下一个点或字符串的末尾: text = "hello there. I would like to capture from this point till the end" capture= re.findall(r'(point).$',text) print (capture) 在这里,(.*?是一个捕获组,它在一段时间内匹配任何字符0次或更多次(?:\.|$)是一个与点或字符串结尾匹配的非捕获组 演示: 假设您希望

有人能告诉我我做错了什么吗?谢谢。

假设您要捕获某个单词后的所有内容,直到下一个点或字符串的末尾:

text = "hello there. I would like to capture from this point till the end"
capture= re.findall(r'(point).$',text)
print (capture)
在这里,
(.*?
是一个捕获组,它在一段时间内匹配任何字符0次或更多次
(?:\.|$)
是一个与点或字符串结尾匹配的非捕获组

演示:


假设您希望捕获某个单词后的所有内容,直到下一个点或字符串末尾:

text = "hello there. I would like to capture from this point till the end"
capture= re.findall(r'(point).$',text)
print (capture)
在这里,
(.*?
是一个捕获组,它在一段时间内匹配任何字符0次或更多次
(?:\.|$)
是一个与点或字符串结尾匹配的非捕获组

演示:


你是说
*
?在
和字符串结尾之间没有精确的一个字符。哦,不,不,我的意思是我想从单词点一直捕捉到句子的结尾:“…点到结尾”是的,除非那正好是一个字符,
$
无法匹配。哦,是的,但它不包括“点”这个词。那么我真的可以把它也包括在这个代码中吗?哦,对不起,我知道了~是的!非常感谢。。。非常简单..你是说
*
?在
和字符串结尾之间没有精确的一个字符。哦,不,不,我的意思是我想从单词点一直捕捉到句子的结尾:“…点到结尾”是的,除非那正好是一个字符,
$
无法匹配。哦,是的,但它不包括“点”这个词。那么我真的可以把它也包括在这个代码中吗?哦,对不起,我知道了~是的!非常感谢。。。非常简单..谢谢@alecxe这很好用!非常感谢!它为我提供了很多解决方案!即使过了一段时间,这也是您提供的非常有用的脚本!谢谢@alecxe,这很好用!非常感谢!它为我提供了很多解决方案!即使过了一段时间,这也是您提供的非常有用的脚本!
>>> 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']