GWT-提取两个字符之间的文本

时间:2019-02-08 17:22:13

标签: java regex gwt substring

在GWT中,我有一个servlet,它从数据库返回图像到客户端。我需要提取字符串的一部分才能正确显示图像。 chrome,firefox和IE返回的内容在src部分带有斜线。例如:String s =“ src = \”“;在下面的字符串中看不到。也许斜杠在http字符串周围添加了更多的括号。我不确定吗?

  what is returned in those 3 browsers is = <img style="-webkit-user-select: none;" src="http://localhost:8080/dashboardmanager/downloadfile?entityId=4886">

EDGE浏览器的src中没有斜线,因此我提取图像的方法在edge中不起作用

返回的边:

String edge = "<img src=”http://localhost:8080/dashboardmanager/downloadfile?entityId=4886”>";

问题:我需要提取下面的字符串。

http://localhost:8080/dashboardmanager/downloadfile?entityId=4886

使用src =或src = \

我尝试并与不带括号“ src = \”返回的浏览器一起使用的方法:

String s = "src=\"";
int index = returned.indexOf(s) + s.length();
image.setUrl(returned.substring(index, returned.indexOf("\"", index + 1)));

但是由于不能返回斜线而无法在EDGE中工作

我无权访问GWT中的模式和匹配器。

我如何提取并记住EntityId号将更改 http://localhost:8080/dashboardmanager/downloadfile?entityId=4886

上面的返回什么字符串中的

编辑:

我需要一种通用方法来提取http://localhost:8080/dashboardmanager/downloadfile?entityId=4886

当字符串看起来都像这样的时候。

String edge = "<img src=”http://localhost:8080/dashboardmanager/downloadfile?entityId=4886”>";

3 browsers is = <img style="-webkit-user-select: none;" src="http://localhost:8080/dashboardmanager/downloadfile?entityId=4886">

1 个答案:

答案 0 :(得分:1)

    public static void main(String[] args) {
        String toParse = "<img style=\"-webkit-user-select: none;\" src=\"http://localhost:8080/dashboardmanager/downloadfile?entityId=4886\">";    
        String delimiter = "src=\"";
        int index = toParse.indexOf(delimiter) + delimiter.length();
        System.out.println(toParse.substring(index, toParse.length()).split("\"")[0]);      
    }
相关问题