正则表达式模式需要帮助

发布于 2024-08-12 09:15:03 字数 759 浏览 1 评论 0原文

原始字符串是这样的:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\froman\fcharset0 Times New Roman;}{\f1\fnil\fcharset0 MS Shell Dlg 2;}}
\viewkind4\uc1\pard\sb100\sa100\f0\fs24\u30340?\u27494?\u35013?\u20998?\u23376?\u65292?23\u26085?\u22312?\u33778?\u24459?\u23486?\u21335?\u37096?\u30340?\u39532?\u20140?\par
\pard\f1\fs17\par
by: lena (11/26/09)\par
\par
}

将斜杠后面的所有 RTF 标记替换为除 \unumbers 之外的“”空字符串的正则表达式模式是什么? 结果应该如下所示:

\u30340?\u27494?\u35013?\u20998?\u23376?\u65292?23\u26085?\u22312?\u33778?\u24459?\u23486?\u21335?\u37096?\u30340?\u39532?\u20140?
by: lena (11/26/09)

我尝试了 "\\\\\\w+|\\{.*?\\}|\\}" ,它删除了反斜杠和所有大括号后面的所有内容。缺少的部分类似于 \\!(\\\\u)

The raw string is like this:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\froman\fcharset0 Times New Roman;}{\f1\fnil\fcharset0 MS Shell Dlg 2;}}
\viewkind4\uc1\pard\sb100\sa100\f0\fs24\u30340?\u27494?\u35013?\u20998?\u23376?\u65292?23\u26085?\u22312?\u33778?\u24459?\u23486?\u21335?\u37096?\u30340?\u39532?\u20140?\par
\pard\f1\fs17\par
by: lena (11/26/09)\par
\par
}

What is the regex pattern that would replace all RTF tags following a slash with "" empty string except \unumbers?
The result should look like:

\u30340?\u27494?\u35013?\u20998?\u23376?\u65292?23\u26085?\u22312?\u33778?\u24459?\u23486?\u21335?\u37096?\u30340?\u39532?\u20140?
by: lena (11/26/09)

I tried "\\\\\\w+|\\{.*?\\}|\\}" which removes all that follows a backslash and all curly braces. The missing part is something like \\!(\\\\u)

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

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

发布评论

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

评论(1

疧_╮線 2024-08-19 09:15:03

首先尝试匹配您要保留的标签并替换它们。

# php
$str = preg_replace('/(\\\u[\d]+)|\\\+[\w\?]+|{.*?}/', '$1', $str);

# perl
$str =~ s/(\\\u[\d]+)|\\\+[\w\?]+|{.*?}/$1/g;

Try matching the tags you want to keep first and replace them.

# php
$str = preg_replace('/(\\\u[\d]+)|\\\+[\w\?]+|{.*?}/', '$1', $str);

# perl
$str =~ s/(\\\u[\d]+)|\\\+[\w\?]+|{.*?}/$1/g;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文