Java 用特殊字符替换符号和的正则表达式模式

Java 用特殊字符替换符号和的正则表达式模式,java,regex,for-loop,ampersand,Java,Regex,For Loop,Ampersand,我需要更换https://9S&Re与https://9S#Re这样我就可以避免分裂逻辑。我的目标是获得“用户图像”键和值https://9S&Re“。但是当我使用带“&”的split时,它给出了错误的结果。因此,我尝试使用正则表达式模式,它将在&*&之间进行检查,如果中间没有等于,则表示在其中一个查询值中有一个与符号。非常感谢您的帮助 import java.nio.charset.Charset; import java.util.HashMap; import java.u

我需要更换
https://9S&Re
https://9S#Re
这样我就可以避免分裂逻辑。我的目标是获得“用户图像”键和
值https://9S&Re“
。但是当我使用带“&”的split时,它给出了错误的结果。因此,我尝试使用正则表达式模式,它将在&*&之间进行检查,如果中间没有等于,则表示在其中一个查询值中有一个与符号。非常感谢您的帮助

import java.nio.charset.Charset;
    import java.util.HashMap;
    import java.util.List;

    import org.apache.http.NameValuePair;
    import org.apache.http.client.utils.URLEncodedUtils;

    public class OAuthTest {

        public static void main(String[] args) {
            try {
                //HashMap paramHashMap=new HashMap();           
                List<NameValuePair> args2= URLEncodedUtils.parse("tool=canvas&tool_guid=8314&user_image=https://9S&Re&launch_presentation_document_target=iframe", Charset.forName("UTF-8"));
                for (NameValuePair arg:args2)
                    System.out.println(arg.getName()+"="+arg.getValue().replaceAll("#","&"));

            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }
import java.nio.charset.charset;
导入java.util.HashMap;
导入java.util.List;
导入org.apache.http.NameValuePair;
导入org.apache.http.client.utils.URLEncodedUtils;
公共类OAuthTest{
公共静态void main(字符串[]args){
试一试{
//HashMap paramHashMap=新HashMap();
列表args2=URLEncodedUtils.parse(“工具=canvas&tool\u guid=8314&user\u image=https://9S&Re&launch_presentation_document_target=iframe,Charset.forName(“UTF-8”);
对于(NameValuePair arg:args2)
System.out.println(arg.getName()+“=”+arg.getValue().replaceAll(“#“,”&”);
}捕获(例外e){
e、 printStackTrace();
}
}
}

在for循环中,您是否试图用#替换&?你的论点被改变了