繁体   English   中英

拆分关于除 Python 中的 url 和电子邮件地址之外的所有点字符 (.) 的字符串

[英]Split a string about all dot characters(.) except urls and email addresses in Python

我是正则表达式的相对新手。 我在 Python 中有一个非常简单的用例,但我无法找到最简单的方法。 我有一段要分成句子。 这是一个解释某些步骤的技术段落,所以我现在使用一个非常简单的东西,它是关于所有点(。)的分裂但是,该段落也可能有一些 URL 或电子邮件地址,其中可能包含一个点(。)但是我不想把它们分开。 一种方法是从段落中取出所有 URL 和电子邮件地址(使用正则表达式?)然后拆分是关于 (.) 然后添加回 URL 等。我假设必须有更好的方法来实现这一点通过使用正则表达式库中的 split 函数和适当的正则表达式。 提供一个例子来清楚:

input= "Click on the next button. If you do not see this option, you may contact: xyz@support.com. Please mention your user id in the email"
output= ["click on the next button", "If you do not see this option, you may contact: xyz@support.com", "Please mention your user id in the email"]
outp = inp.split('. ') #Will not trigger on URLS and email adresses

假设段落中没有语法错误。

\.\s*(?=[A-Z])

您可以按此拆分。请参阅演示。

https://regex101.com/r/AayT6H/1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM