We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Java Regex 2 - Duplicate Words
Java Regex 2 - Duplicate Words
Sort by
recency
|
353 Discussions
|
Please Login in order to post a comment
Yes I'm generating the expected ouput but test still fail
this is broken
String regex = "\b(\w+)(\b\W+\b\1\b)*"; Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); input = input.replaceAll("\b" + Pattern.quote(m.group()) + "\b", m.group(1));
The Pattern.quote method quotes part of a regex pattern to make regex interpret it as string literals.
import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern;
public class DuplicateWords {
}