I am trying to find and remove duplicated words in a LaTeX file.
Right now I am using query-replace-regexp
with the regular expression
\b\(\w+\)[ #]+\1
where #
stands for line-break (C-q C-j
). This does not ignore case, however, and misses the following repetition of the word 'the':
I am the new organ player. The the new keymaster.
Are regular expressions sufficient for this or it's better to program a lisp function to go word by word, checking whether consecutive words are the same?