正则表达式替换“节字符”在java中

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

我正在运行一系列正则表达式替换(即 String.replaceAll 调用),将文本文件中的所有特殊字符转换为 XML 可解析的特殊字符。例如:

string_out = string_out.replaceAll("&", "&");

我在替换“节字符”时遇到了障碍,即这个小波浪线:§

对于初学者,我正在 vi 中进行编辑,所以我什至无法将字符粘贴到那里,它是不是标准或扩展 ASCII 的成员。出于同样的原因,我也看不到在正则表达式中通过十六进制代码指定它。

您将如何为正则表达式替代指定此字符?或者,如果您只是想过来告诉我,已经有一个函数隐藏在某个地方来完成我手动进行的字符转换,那也很酷。

I'm running a series of regex substitutions (i.e. String.replaceAll calls) to convert all the special characters in a text file to XML parseable special characters. For example:

string_out = string_out.replaceAll("&", "&");

I've hit a stumbling block replacing the 'section character' that is, this little squiggle: §

For starters, I'm doing my editing in vi, so I can't even paste the character in there, it being not a member of standard or extended ascii. I can't see specifying it by hex code in the regex working either, for the same reason.

How would you specify this character for a regex substitute? Or if you just want to drop in and tell me there's already a function tucked away somewhere to do the character conversion I'm doing by hand, that's cool, too.

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

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

发布评论

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

评论(2

岛歌少女 2024-09-22 03:08:12
Unicode: §
Hex:     0xA7
html:    §
name:    section sign

您可以在 latin-1 补充中找到它。

Unicode: §
Hex:     0xA7
html:    §
name:    section sign

You can find it in the latin-1 supplement.

浪漫人生路 2024-09-22 03:08:12

你不能简单地使用 unicode 代码点吗?

cant you simply use the unicode codepoint?

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