top of page

Regex to find where consecutive lines end with the same text

Tonight's tip features a regular expression script created by The fourth bird of the Netherlands on stack overflow. I posted looking for a regular expression that would find the text on a line repeated from the prior line after a time code at the beginning of the both lines that might be different. See this example:


(11:12:21) [Tom]: Hello this is Tom. Who is it?

(11:14:08) [Tom]: Hello this is Tom. Who is it?


The goal was to find when consecutive lines were the same after the first 10 characters. The fourth bird came up with a solution that would find when parts of two lines matched. In a text editor like NotePad++ run this find and replace search:


FIND: ^(\([^][]*\))(.*)(?:\r?\n\([^][]*\)\2)+

REPLACE: $1$2


^(\([^][]*\)) will find the first part of the string - the time code in parentheses. So the caret ^ matches the beginning of the line, and the rest then finds the rest of the text between the parentheses.


(.*) matches to the end of the line after the parenthetical information at the beginning.


(?:\r?\n this then matches a new group on a new line


\([^][]*\) this matches from the first part of the previous line.


\2)+ this then matches with the second part of the previous line.



As you can see in this demonstration a find and replace in the text editor can easily remove the duplicate lines.









3 comentários


BFVY IRTO
BFVY IRTO
28 de dez. de 2024

代发外链 提权重点击找我;

游戏推广 游戏推广;

Fortune Tiger Fortune Tiger;

Fortune Tiger Slots Fortune…

谷歌马甲包/ 谷歌马甲包;

谷歌霸屏 谷歌霸屏;

מכונות ETPU מכונות ETPU;

;ماكينات اي تي بي…

آلات إي بي بي…

ETPU maşınları ETPU maşınları;

ETPUマシン ETPUマシン;

ETPU 기계 ETPU 기계;

Curtir

WKDU TRBD
WKDU TRBD
28 de dez. de 2024

代发外链 提权重点击找我;

谷歌蜘蛛池 谷歌蜘蛛池;

Fortune Tiger Fortune Tiger;

Fortune Tiger Slots Fortune…

谷歌权重提升/ 谷歌权重提升;

谷歌seo 谷歌seo;

מכונות ETPU מכונות ETPU;

Машини ETPU Машини ETPU

ETPU-Maschinen ETPU-Maschinen

EPS-машины EPS-машины

ЭПП-машины ЭПП-машины� بي يو

ETPU maşınları ETPU maşınları

ETPUマシン ETPUマシン

ETPU 기계 ETPU 기계

Curtir

AVXJ KAZD
AVXJ KAZD
26 de dez. de 2024

代发外链 提权重点击找我;

google留痕 google留痕;

Fortune Tiger Fortune Tiger;

Fortune Tiger Fortune Tiger;

Fortune Tiger Slots Fortune…

站群/ 站群;

万事达U卡办理 万事达U卡办理;

VISA银联U卡办理 VISA银联U卡办理;

U卡办理 U卡办理;

万事达U卡办理 万事达U卡办理;

VISA银联U卡办理 VISA银联U卡办理;

U卡办理 U卡办理;

온라인 슬롯 온라인 슬롯;

온라인카지노 온라인카지노;

바카라사이트 바카라사이트;

EPS Machine EPS Machine;

EPS Machine EPS Machine;

EPS Machine EPS Machine;

EPS Machine EPS Machine;

Curtir
bottom of page