正则表达式替换“节字符”在java中
我正在运行一系列正则表达式替换(即 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在 latin-1 补充中找到它。
You can find it in the latin-1 supplement.
你不能简单地使用 unicode 代码点吗?
cant you simply use the unicode codepoint?