正则表达式引用

发布于 2024-08-03 04:36:43 字数 714 浏览 4 评论 0原文

我已经在这里获得了创建报价提取功能的帮助。非常感谢,soulmerge!

现在我正在寻找正则表达式(PHP)来提取引用的文本和引用的人。人物应该在一个索引(子字符串)中,文本在另一个索引(子字符串)中。

对于英文文本,soulmerge 提出了这些正则表达式:

  • /"(.*?)[,.]?\h*"\h*said\h*(.*?)\./
  • /"(.*?)\h*"(.*)said/
  • /\.\h*(.*)(一次)?\h*said[\-]*"(. *?)"/

我想将以下德语直接语音示例“翻译”为正则表达式:

  • “这是一个引文”,sagte PERSON ...
  • “这是一个引文!”,sagte PERSON .. “
  • 这是引文?”,sagte PERSON ...
  • PERSON sagte:“这是引文。”
  • 人说:“这是引言!”
  • 人萨格特:“这是引文?”

有人可以帮助我为这些直接言语形式构建足够的正则表达式吗?

我希望你能帮助我。预先非常感谢您!

I've already got help here for creating a quotation extraction function. Thanks alot, soulmerge!

Now I'm looking for regular expressions (PHP) which extract the cited text and the cited person. The person should be in one index (substring), the text in another index (substring).

For English texts, soulmerge proposed these regexes:

  • /"(.*?)[,.]?\h*"\h*said\h*(.*?)\./
  • /"(.*?)\h*"(.*)said/
  • /\.\h*(.*)(once)?\h*said[\-]*"(.*?)"/

I would like to "translate" the following direct speech examples in German to regexes:

  • "This is a quotation", sagte PERSON ...
  • "This is a quotation!", sagte PERSON ...
  • "This is a quotation?", sagte PERSON ...
  • PERSON sagte: "This is a quotation."
  • PERSON sagte: "This is a quotation!"
  • PERSON sagte: "This is a quotation?"

Can someone help me to build the adequate regular expressions for these direct speech forms?

I hope you can help me. Thank you very much in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦情居士 2024-08-10 04:36:43
  • /"(.+)",\s*sagte\s+(.+)/
  • /(.+)\s+sagte:\s*"(.+)"/

请注意,person 和 Question 变量是相反的第二个正则表达式。

  • /"(.+)",\s*sagte\s+(.+)/
  • /(.+)\s+sagte:\s*"(.+)"/

Please note that the person and question variables are reversed in the second regex.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文