Invalid string literal '^.*\s(\d+)\s.*$'. Illegal character sequence \s' in string literal [duplicate]
I want to use the below regex string: private final String regex = '^.*s(d+)s.*$'; In a Pattern: private Pattern pattern = Pattern.compile(regex); But I am getting this error: Illegal string literal: Invalid string literal '^.s(d+)s.$'. Illegal character sequence s' in string literal. What do I need to do to fix this? Top keywords - *
Escape all the characters with more character of course!
private final String regex = '^.*\s(\d+)\s.*$';
Hope this will help you solve your error.