I want to calculate the total liabilities amount from webtable and need to compare with the total amount which is present on webpage.

I got the following error :

Illegal/unsupported escape sequence near index 1

My code is :

totalLiabilities = driver.findElement(By.xpath(".//*[contains(text(),'Liabilities :')]")).getText();
        Pattern patt = Pattern.compile("[-+^:$,a-zA-Z0-9]");
        Matcher matchh = patt.matcher(totalLiabilities);
            String s2 = matchh.group();
            totalLiabilities = totalLiabilities.replaceAll("\\"+s2, "");
        totalLiabilities=totalLiabilities.replace("Liabilities", "");
        logger.info("total liabilities : "+totalLiabilities);

1 Answer 1


Try using replace instead of replaceAll. replace would also replace all the occurrences but won't use regular expression for that - just a char sequence. If you still need to replace the values by a regular expression you need to add \\ to your double-slash.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.