今さらPython

正規表現はテキスト処理の華よね!

サンプルコード

こんな感じね。

#!/usr/bin/env python3

import os
import re
import sys

for e in sys.argv:
   if(os.path.basename(__file__) != e and ("./" + os.path.basename(__file__)) != e):
       print(os.path.basename(__file__))
       with open(e) as f:
           for x in f:
               y = re.sub(r'\t+','\t',x)
               z = re.sub(r'^(\d+\t\d+\t\d+\t\d+)\t','\\1_',y);y=z
               z = re.sub(r'^(\d+)\t(\d+)\t(\d+)\t(\d+)_','\\1.\\2.\\3.\\4_',y);y=z
               z = re.sub(r'[\r\n]','',y);y=z
               z = re.sub(r'^(1)','\n\\1',y);y=z
               z = re.sub(r'\t(①)','\n\\1',y);y=z
               z = re.sub(r'"','',y);y=z
               z = re.sub(r'^\t','',y);y=z
               z = re.sub(r'\tMENU','\nMENU',y);y=z
               print(y)

よし。


トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2023-06-28 (水) 18:49:08