Skip to content

Instantly share code, notes, and snippets.

@KatagiriSo
Created October 22, 2020 11:33
Show Gist options
  • Save KatagiriSo/71900cfaaab20fd82199522a94de0bb9 to your computer and use it in GitHub Desktop.
Save KatagiriSo/71900cfaaab20fd82199522a94de0bb9 to your computer and use it in GitHub Desktop.
最後のカンマをみつける
import re
import glob
txt = "hogehoge[abccbbss, bccc, [caaa, caaa], abb,]"
def matchlastComma(txt):
pattern = r"(.*),"
m = re.findall(pattern, txt, flags=(re.MULTILINE | re.DOTALL))
if len(m) == 0:
return txt
return(m[0] + "]")
paths = glob.glob("./*.json")
for path in paths:
fileText = ""
with open(path, mode="r") as f:
fileText = f.read()
print(matchlastComma(fileText))
with open(path, mode="w") as f:
f.write(matchlastComma(fileText))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment