You can use the regex, Thread\s*\.\s*sleep\s*\(\s*\d+\s*\)
.
Explanation of the regex:
Thread
: Literal, Thread
\s*\.\s*
: .
preceded by and followed by 0+ whitespace characters
sleep\s*
: Literal, sleep
followed by 0+ whitespace characters
\(\s*
: The character, (
followed by 0+ whitespace characters
\d+\s*
: One or more digits followed by 0+ whitespace characters
\)
: The character, )
Demo:
public class Main {
public static void main(String[] args) {
String x = "Some Thread.sleep(1000) text";
x = x.replaceAll("Thread\\s*\\.\\s*sleep\\s*\\(\\s*\\d+\\s*\\)", "");
System.out.println(x);
}
}
Output:
Some text