gpt4 book ai didi

句子的正则表达式,但遗漏了网站

转载 作者:行者123 更新时间:2023-12-04 10:59:45 25 4
gpt4 key购买 nike

我正在寻找一个不会破坏网站的句子正则表达式。

我的正则表达式是:(\(?[^\.]+[\.!\?]\)?) .

对于示例文本,我想要
This is a paragraph of text. It is very interesting. Yet for a test website like google.com.xyz it's broken up.
变成三句话:

  • 这是一段文字。
  • 这很有趣。
  • 然而,对于像 google.com.xyz 这样的测试网站来说,它已经被打破了。

  • 然而,最后一句话被分成三次:
  • 然而对于像谷歌这样的测试网站。
  • com。
  • xyz 已经分手了。

  • 如何修改我的正则表达式以确保网站也不会陷入这种情况?

    最佳答案

    您可以尝试查找与以下正则表达式模式的所有匹配项:

    (.*?\.)(?!\S)\s*

    Python 中的示例脚本:
    inp = "This is a paragraph of text. It is very interesting. Yet for a test website like google.com.xyz it's broken up."
    parts = re.findall(r'(.*?\.)(?!\S)\s*', inp)
    print(parts)

    这打印:
    ['This is a paragraph of text.',
    'It is very interesting.',
    "Yet for a test website like google.com.xyz it's broken up."]

    以下是正则表达式模式的解释:
    (.*?\.)   match AND capture all content up to and including a full stop
    (?!\S) which is followed by whitespace or end of the string
    \s* then consume any whitespace after the full stop but before the next sentence

    关于句子的正则表达式,但遗漏了网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58897924/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com