$string = "Apple
Foo
Banana
...
Banana
Foo
Other text
...
Apple";
I have text where single rows are duplicated after a row “…”.
The rows before and after that can be anything (“Foo”), but also be a duplicate (without “…” like “Apple”).
The “…”-row can appear multiple times without a duplicate row after it.
I only want to remove duplicated rows which have a “…” row inbetween.
In other words: Remove the line after “…” if it’s the same as above “…”
How can I match
Banana
...
Banana
to remove the duplicated row:
Banana
so the result is
$string = "Apple
Foo
Banana
...
Foo
Other text
...
Apple";
Cheers!
If the task is to just remove the line following the line with three dots:
The expression matches:
The
/mmodifier is used to select multi-line mode, in which^and$carry the meaning of start and end of the line.The
\\1back reference is used to match whatever was before the three dots.The replacement
'\\1'is needed to place back the matched line with three dots.