如何删除字符串中的任何插入符号?
我使用的正则表达式字符串在其内部某处包含克拉 (^) 符号。 Java中有没有办法删除这些符号?以下是我尝试过的几种方法:
string = "some^string";
string = string.replaceAll("\\^", "");
string = string.replaceAll(Pattern.quote("\\^"), "");
string = string.replaceAll(Pattern.quote("\u2038"), "");
没有一个有效。我缺少什么?
I'm using a regex string that contains a carat (^) symbol somewhere inside of it. Is there a way in Java to remove these symbols? Here are a few methods I've tried:
string = "some^string";
string = string.replaceAll("\\^", "");
string = string.replaceAll(Pattern.quote("\\^"), "");
string = string.replaceAll(Pattern.quote("\u2038"), "");
None of which have worked. What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根本不需要使用正则表达式:
但是,您的第一个示例也有效:
...所以您的问题完全有可能在其他地方。
There's no need to use regular expressions at all:
However, the first of your examples works too:
... so it's entirely possible that your problem is elsewhere.
string.replaceAll("\\^", "");
应该可以。string.replaceAll("\\^", "");
should work.请。删除代码上方的最后两行,然后在下面写一些内容,然后再检查。
字符串=“一些^字符串”;
string = string.replaceAll("\^", "");
Pls. delete last 2 lines from above your code and do write below things only then check.
string = "some^string";
string = string.replaceAll("\^", "");
我认为您可以尝试使用另一个变量名称,例如:
并使用新的
str1
,而不是旧的string
。I think you can try using another variable name, like for example:
and use the new
str1
, instead of the oldstring
.