簡體   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