All this cause my brain can't undersant regex

This commit is contained in:
2022-07-12 00:22:49 +02:00
parent 2d6b537315
commit 62e485977d
2 changed files with 29 additions and 13 deletions

View File

@ -70,6 +70,22 @@ def FindAllIndex(Str, Sub):
yield i
i = Str.find(Sub, i+1)
def ReplWithEsc(Str, Find, Repl, Esc='\\'):
New = ''
Sects = Str.split(Find)
for i,e in enumerate(Sects):
if i == 0:
New += e
elif i > 0:
if Sects[i-1].endswith(Esc*2):
New = New[:-1]
New += Repl + e
elif Sects[i-1].endswith(Esc):
New += Find + e
else:
New += Repl + e
return New
def GetFullDate(Date):
if not Date:
return None