gpt4 book ai didi

Lua 模式匹配

转载 作者:行者123 更新时间:2023-12-03 23:28:30 25 4
gpt4 key购买 nike

我有一个文件,该文件是从具有 RTF 格式标签的 Microsoft Lync 对话中提取值而获得的。示例文件如下:

{\rtf1\fbidis\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 >Segoe UI;}{\f1\fnil Segoe UI;}} {\colortbl ;\red0\green0\blue0;} {*\generator Riched20 15.0.4420}{*\mmathPr\mwrapIndent1440 }\viewkind4\uc1 \pard\cf1\embo\f0\fs20 Craig...\embo0 \embo please\embo0 \embo close\embo0 \embo >out\embo0 \embo of\embo0 \embo your\embo0 \embo old\embo0 \embo client\embo0 \embo >and\embo0 \embo re-open\embo0\f1\par {*\lyncflags rtf=1}}

我正在尝试使用 Lua 脚本删除 RTF 标签并只提取对话文本。所以我的函数的结果应该是:

Craig... please close out of your old client and re-open

我试过使用带有正则表达式的 string.gsub 来匹配模式并用空格替换它们以仅保留文本但它不起作用。这是我目前为 string.gsub 编写的代码:

result = string.gsub(s, "\{\*?\\[^{}]+}|[{}]|\\\n?[A-Za-z]+\n?(?:-?\d+)?[ ]?", " ")

如有任何建议,我们将不胜感激!

附加:

user1@capital.com @ 2013-01-18 17:48:03Z (TO: user2@capital.com)

{\rtf1\fbidis\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 Segoe UI;}{\f1\fnil Segoe UI;}}{\colortbl ;\red0\green0\blue0;}{*\generator Riched20 15.0.4420}{*\mmathPr\mwrapIndent1440}\viewkind4\uc1\pard\cf1\embo\f0\fs20 works\embo0\embo for\embo0\embo me..\embo0\embo how\embo0\embo about\embo0\embo embedding\embo0\embo pictures?\embo0\f1\par{*\lyncflags rtf=1}}

user1@capital.com @ 2013-01-18 17:48:57Z (TO: user2@capital.com)

{\rtf1\fbidis\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 Segoe UI;}{\f1\fnil Segoe UI;}}{\colortbl ;\red0\green0\blue0;}{*\generator Riched20 15.0.4420}{*\mmathPr\mwrapIndent1440}\viewkind4\uc1\pard\cf1\embo\f0\fs20 I\embo0\embo see\embo0\embo it\embo0\f1\par{*\lyncflags rtf=1}}

user1@capital.com @ 2013-01-18 17:49:27Z (TO: user2@capital.com)

{\rtf1\fbidis\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 Segoe UI;}{\f1\fnil Segoe UI;}}{\colortbl ;\red0\green0\blue0;}{*\generator Riched20 15.0.4420}{*\mmathPr\mwrapIndent1440}\viewkind4\uc1\pard\cf1\embo\f0\fs20 let's\embo0\embo try\embo0\embo a\embo0\embo meeting.\embo0\f1\par{*\lyncflags rtf=1}}

最佳答案

Lua 模式没有 运算符(|)或可选的分组((?:...)?)。这样的事情可能会起作用:

s:match("{(.+)}"):gsub("%b{}", ""):gsub("\\%w+", "")

将返回:

"    Craig...  please  close  >out  of  your  old  client  >and  re-open "

第一个 gsub 删除所有 {} 对及其内容,第二个 gsub 删除所有 rtf 标签(尽管似乎有有些允许在其中留出空格,因此您可能需要调整模式)。

关于Lua 模式匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14696727/

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