Created
October 22, 2020 11:33
-
-
Save KatagiriSo/71900cfaaab20fd82199522a94de0bb9 to your computer and use it in GitHub Desktop.
最後のカンマをみつける
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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