You can use the regex, (?<=contractor:\").*(?=\" client:)
Description of the regex:
(?<=contractor:\")
specifies positive lookbehind for contractor:\"
.*
specifies any character
(?=\" client:)
specifies positive lookahead for \" client:
In short, anything preceded by contractor:\"
and followed by \" client:
Demo:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
String str = "contractor:\"Hi, this is \\\"Paul\\\", how are you?\" client:\"Hi ....\"";
String regex = "(?<=contractor:\").*(?=\" client:)";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}
Output:
Hi, this is \"Paul\", how are you?