dazimo

Regex Remover - Fixed

Apr 14th, 2023 (edited)
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. import re
  2.  
  3. # Open input file for reading and output file for writing
  4. with open("taereltxt.txt", "r") as input_file, open("output.txt", "w") as output_file:
  5.  
  6.     input = input_file.read()
  7.    
  8.     regexList = []
  9.  
  10.     # List of patterns to remove. Add as many as needed.
  11.     regexList.append("(==History==|==Stone Age: Before 1E 0==|==Copper Age: 1E 1-1E 2200==|==Bronze Age: 1E 2200-1E 4400==|==Iron Age: 2E 0-2E 700==|==Ancient Age: 2E 700-2200==|==Middle Ages: 3E 0-2050==|==Early Modern Age: 2050-3E 2600==|==Industrial Age: 3E 2600-3E 2700==|==Machine Age: 3E 2700-3E 2800==|==Atomic Age: 3E 2800-3E 2850==|==Space Age: 2E 2850-2E 2900==|==Information Age: 3E 2850-3E 2900==|==Genetic Age: 3E 2950-3E 3000==|Awakening Age: 3E 3000-3E 3415==|==Shattering Age: 4E 0 - 4E 250==|==History|Geography|Plants|Animals|Biology==|==Psychology==|==Culture==|==Government==|==Military==|==Religion==|==Miscellany==|==History (A'voreld kin'toni Clan)==|==Biology (A'voreld kin'toni Clan)==|==Psychology (A'voreld kin'toni Clan)==|==Culture (A'voreld kin'toni Clan)==|==Government (A'voreld kin'toni Clan)==|==Military (A'voreld kin'toni Clan)==|==Religion (A'voreld kin'toni Clan)==|==Miscellany (A'voreld kin'toni Clan)==|\sTaerel:.?|\sCategory:.?)")
  12.     regexList.append("\{\{[\s\S]*?\}\}")
  13.     regexList.append("\[\[Category:.+?\]\]")
  14.     regexList.append("\[\[Taerel:.+?\]\]")
  15.  
  16.  
  17.     # Remove matches from the file
  18.     for pattern in regexList:
  19.         input = re.sub(pattern, "", input)
  20.    
  21.     # Output to new file
  22.     output_file.write(input)
Advertisement
Add Comment
Please, Sign In to add comment