gpt4 book ai didi

javascript - 句号、单词和冒号的正则表达式

转载 作者:行者123 更新时间:2023-12-05 08:25:21 26 4
gpt4 key购买 nike

是否有正则表达式、python 或 javascript 方法来搜索句点、单词和定义,然后将其附加到字典或其他对象?

例如:

. Reversion: A reversion is turning back again to a previous state or condition. Rhetoric: Rhetoric is the skill or art of using language to persuade or influence people, especially language that sounds impressive but may not be sincere or honest.

这将变成 {"Reversion": "A reversion is going again back to a previous state or condition", "Rhetoric": "Rhetoric is the skill or art of using language to persuase or influence people, especially听起来令人印象深刻但可能不真诚或诚实的语言”

最佳答案

过滤掉单词和定义的正则表达式是:

\.\s*([^:]*)\s*:\s*([^.]*)

演示:https://regex101.com/r/utgrCb/1/

  • \.\s* 起始点和可选空格
  • ([^:]*)“单词”是冒号前的所有内容
  • \s*:\s* 冒号用可选空格包围
  • ([^.]*)“定义”是最后一个点之前的所有内容

关于javascript - 句号、单词和冒号的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66022702/

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