我有点新手,所以我有以下字符串:
[[ChromeDriver: chrome on LINUX (ff108507ea7a3598104c728cc453f299)] -> xpath: /html[1]/body[1]/div[3]/div[1]/header[1]/div[1]/div[1]/div[1]/div[1]/nav[1]/ul[1]/li[1]/a[1]] (class: sf-depth-1 menuparent ext sf-with-ul)
我想知道如何在/html
之前删除所有内容,因此我最终以以下字符串: /html [1]/身体[1]/div [3]/div [1]/header [1]/div [1]/div [1]/div [1]/div [1]/div [1]/nav [1]/ul [1]/li [1]/a [1]](类:sf-depth-1 menuparent sf-with-with-ul(
我尝试过,但没有成功:
Pattern pattern = Pattern.compile("/html.*");
Matcher matcher = pattern.matcher(absoluteXpath);
if (matcher.find()) {
System.out.println(matcher.group(1));
}
在这里测试:
https://regexr.com/4gff0
不需要正则...只需使用:
String str = "[[ChromeDriver: chrome on LINUX (ff108507ea7a3598104c728cc453f299)] -> xpath: /html[1]/body[1]/div[3]/div[1]/header[1]/div[1]/div[1]/div[1]/div[1]/nav[1]/ul[1]/li[1]/a[1]] (class: sf-depth-1 menuparent ext sf-with-ul)";
str = str.substring(str.indexOf("/html"));