-1

I'm kinda new to regex, so I have the following string:

[[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)

I want to know how I can remove everything before the /html, so I end up with the following string: /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)

I tried this but without success:

Pattern pattern = Pattern.compile("/html.*");
Matcher matcher = pattern.matcher(absoluteXpath);

if (matcher.find()) {
    System.out.println(matcher.group(1));
}

Tested here:

https://regexr.com/4gff0

Michał Turczyn
  • 32,028
  • 14
  • 47
  • 69
sdf68dsf7
  • 61
  • 8

1 Answers1

0

No need for regex... just use:

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"));
Michał Turczyn
  • 32,028
  • 14
  • 47
  • 69