title: Regex in java for finding duplicate consecutive words
body: <p>I saw this as an answer for finding repeated words in a string. But when I use it, it thinks <code>This</code> and <code>is</code> are the same and deletes the <code>is</code>.</p>
  
  <p>Regex</p>
  
  <pre><code>"\\b(\\w+)\\b\\s+\\1"
  </code></pre>
  
  <p>Any idea why this is happening?</p>
  
  <p>Here is the code that I am using for duplicate removal</p>
  
  <pre><code>public static String RemoveDuplicateWords(String input)
  {
      String originalText = input;
      String output = "";
      Pattern p = Pattern.compile("\b(\w+)\b\s+\b\1\b", Pattern.MULTILINE+Pattern.CASE_INSENSITIVE); 
      //Pattern p = Pattern.compile("\\b(\\w+)\\b\\s+\\1", Pattern.MULTILINE+Pattern.CASE_INSENSITIVE);
      Matcher m = p.matcher(input);
      if (!m.find())
          output = "No duplicates found, no changes made to data";
      else
      {
          while (m.find())
          {
              if (output == "")
                  output = input.replaceFirst(m.group(), m.group(1));
              else
                  output = output.replaceAll(m.group(), m.group(1));
          }
          input = output;
          m = p.matcher(input);
          while (m.find())
          {
              output = "";
              if (output == "")
                  output = input.replaceAll(m.group(), m.group(1));
              else
                  output = output.replaceAll(m.group(), m.group(1));
          }
      }
      return output;
  }
  </code></pre>