相关疑难解决方法(0)

Regular expression ^\\Q & \\E

I have below code in my application:

private String getRequestPath(HttpServletRequest req) {
        String path = req.getRequestURI();
        path = path.replaceFirst( "^\\Q" + req.getContextPath() + "\\E", "");
        path = URLDecoder.decode(path);
        System.out.println("req.getRequestURI()="+req.getRequestURI());
        System.out.println("path="+path);
        return path;
    }
Run Code Online (Sandbox Code Playgroud)

In the output I can see below messages when I try to access the servlet which this method belongs to:

req.getRequestURI()=/MyApp/test
path=/test
Run Code Online (Sandbox Code Playgroud)

How the ^\\Q & \\E works in regular expressions.

java regex

5
推荐指数
1
解决办法
8564
查看次数

标签 统计

java ×1

regex ×1