I am currently using regex in Java and want to try and find duplicate words in strings. If I entered a line such as "It's great." I used \\b(\\w+) \\1\\b, but it only recognizes two duplicate words, such as "this this" in a string.
\\b(\\w+) \\1\\b
Any help on this?
Add the ignore case switch to your regular expression (?i):
(?i)
(?i)\\b(\\w+) \\1\\b
Alternatively, you can first collapse the input to lowercase:
input.toLowerCase()
. String.matches(), , .* :
String.matches()
.*
.*(?i)\\b(\\w+) \\1\\b.*
String pattern = "\\b(\\w+)(\\b\\W+\\b\\1\\b)*"; Pattern r = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
Matcher.group() Matcher.group(1), .
Matcher.group()
Matcher.group(1)