[英]ruby regex split string by . but not if its part of an word contained in an exclusion list
我想按特定的字符拆分句子,但是即使此字符不用作排除列表中包含的單詞的一部分也是如此。 例如,我想用句號“”分隔句子。 但是我只是在“ Dr”或“ Prof”之后不使用它。 例如:
“我是物理學博士,我叫Sheldon Cooper。我在帕薩迪納大學工作。”
因此,正則表達式應僅在“ Cooper”之后用句號分隔,而不在“ Dr”之后。
您可以在后面使用否定式:
a = "Im a Dr. of Physics and my Name is Sheldon Cooper. Im working at the University of Pasadena."
a.split(/(?<!Dr|Prof)\./)
#=> ["Im a Dr. of Physics and my Name is Sheldon Cooper", " Im working at the University of Pasadena"]
您可以單獨定義標題。 沒有其他方法可以做到這一點。 您應該這樣設置:Dr | Prof | Assoc
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.