Hi, Nikolaos A. Patsopoulos wrote: > Tim Chase wrote: >>> I have a text that has many occurrences of a pattern . I want to delete >>> every consecutive occurrence, e.g. >>> >>> Pattern Pattern other text Pattern Pattern Pattern Pattern other text >>> Pattern Pattern Pattern >>> should look like this: >>> Pattern other text Pattern other text Pattern >>> >>> I've used: >>> >>> :%s/\(Pattern\s\+\)\(Pattern\)/\1/g >>> >>> but have to run this more than once with: %&g to result the wanted text. >>> >>> Can I do this with one command only? If not can I write a while function?: >>> >> You seem to be close. The following did it for me, >> >> :%s/\(Pattern\)\(\s\+Pattern\)\+/\1/g >> >> or, if you're lazy, >> >> :%s/\(Pattern\)\(\s\+\1\)\+/\1/g >> >> (no need to type the Pattern a 2nd time) > > I tried Jorgen' s code (all possible ways) but I still had to run the > command more than once.
strange, the only difference between Tim's and my versions where the \+ he used after the second parenthesis and the * I used. As both \+ and * are greedy, this should not make a difference for the final result, only maybe in speed. Just out of curiosity could you show me/us the exact command you used? Regards, Jürgen -- Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us. (Calvin)
