My goal is to read in the String and ignore the text in parenthesis.
public static void main(String[] args) {
Pattern checkRegex= Pattern.compile("([a-zA-Z]{3,30}\\s*){2}");
Matcher regexMatcher=checkRegex.matcher("James Hunt(Skateboarder)");
while(regexMatcher.find()){
System.out.println(regexMatcher.group().trim());
}
The current output is:
James Hunt
Skateboarder
Essentially what I want is for the output to be only "James Hunt". What is a suitable Regex pattern to use in this type of situation?
This will work for all non-nested parentheses in your given String:
String input = "James Hunt(Skateboarder)";
String output = input.replaceAll("\\([^)]*?\\)", "");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With