How to remove all String text before equals ('=') sign Java

前端 未结 4 914
自闭症患者
自闭症患者 2021-01-21 07:51

I\'d like to parse a string so I can build an XML document.

I have:

String value = \"path=/Some/Xpath/Here\";

I\'ve parsed it this way

4条回答
  •  花落未央
    2021-01-21 08:47

    Try with:

    private void parseXpath() {
        String s = "path=/Some/Xpath/Here";
        s = s.replace("path=","");
    
        String[] tokens = s.split("/");
        for(String t: tokens){
            System.out.println(t);
        }
    }
    

    Also you can avoid removing it at all, if you get path=/Some/Xpath/Here by other regex, use lookbehind instead of exact matching:

    (?<=path=)[^\\,]*
    

    you should get just /Some/Xpath/Here.

    EDIT If you want to print array as String, use static method Arrays.toString(yourArray);

提交回复
热议问题