替换从javascript获取的字符 [英] Replacing characters got from javascript
问题描述
我正在制作一个从flickr集中提取所有图片的程序。我在代码中发现了一个包含每个图片链接的大字符串,问题是:
i'm making a program that extracts all the pictures from a flickr set. I found in the code a big String with every picture link, the problem is this:
链接具有下一种格式:
https:\/\/c2.staticflickr.com\/4\/3925\/14562233192_3fe2b8fe1b_s.jpg
但是我无法删除'\'字符,尽管使用了\转义序列。
but i'm unable of removing the '\' character, despite using the "\" escape sequence.
我的替换代码如下,ret包含很多以'\ n'分隔的链接:
My replacing code is the following, ret contains a lot of links separated by '\n':
ret =ret.replaceAll("\\", "");
世界上我忘记了什么?
我的错误stackTrace是这样的:
My error stackTrace is this:
Exception in thread "AWT-EventQueue-0" java.util.regex.PatternSyntaxException: Unexpected internal error near index 1
\
^
at java.util.regex.Pattern.error(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at java.util.regex.Pattern.<init>(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at java.lang.String.replaceAll(Unknown Source)
推荐答案
使用4个斜杠而不是2.像这样 - ret = ret.replaceAll(\\\\,)
。你需要1个用于java,一个用于正则表达式引擎,两个用于解析它字面意思(删除特殊含义)。
use 4 slashes instead of 2. Like this - ret =ret.replaceAll("\\\\", "")
. You need 1 for java, one for regex engine, and two to parse it literally (removing the special meaning).
这篇关于替换从javascript获取的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!