cute-pengui · 2022-04-30 09:34
I would like to create a filter using a regular expression to highlight duplicate words in a line. I use the highlight package, which allows me to use regex to highlight certain words. Any ideas of what regex I could use for this purpose?
jsled · 2022-04-30 10:55
Classical regular expressions are not expressive enough to do this … they're not "stateful" in the way you need.
You need "lookaround", which is in the class of "extended regexp"; emacs does not support it natively.
If you have a specific, enumerated wordlist, you could construct a regex that uses lookaround to match each word separately … and as you can generally refer to existing-matched groups, something like…
(foo|bar|baz|quux|…).+(?=\1)
If you have an arbitrary word-list, you could do something like …
([a-zA-Z]{3,6}).*(?=\1)
But that's going to match all sorts of silly things.
You're probably looking to say something more like…
\b([a-ZA-Z]+)\b.+(?=\1)
… to match any "word-boundry"-delimited sequence of characters that shows up later in the string.
Note at the bottom of [emacswiki.org/[…]/RegularExpression](https://www.emacswiki.org/emacs/RegularExpression) that with python available, you can use [visual-regexp-steroids](https://github.com/benma/visual-regexp-steroids.el/) to get access to sufficiently-expressive regexp.
It's not clear to me if the python regexp lib can be used by highlight, tho.
cute-pengui · 2022-04-30 13:14
Thank you so much for your detailed answer. I am going to test this solution and will revert to you.
brwendel · 2022-04-30 20:13
https://github.com/ioah86/repetition\_error\_finder
cute-pengui · 2022-05-02 06:51
Thanks to your direction, I got it to work. Many thanks,