Advertisement
The_Lost_Avatar

anomalous_regex

Aug 24th, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. before = "2015-08-13"
  2. after = "2015-08-25"
  3. full_path = "test.json"
  4. with open(full_path) as infile:
  5. data = infile.read()
  6. data = re.sub(r"(var beforeDate = new Date\().*?(\))", "\\1"+before+"\\2", data)
  7. data = re.sub(r"(var afterDate = new Date\().*?(\))", "\\1"+after+"\\2", data)
  8. with open(full_path, "w") as outfile:
  9. outfile.write(data)
  10.  
  11. and the contents of test.json are the following
  12.  
  13. \n var beforeDate = new Date('2015-08-21');\n var afterDate = new Date('2015-08-19');\n
  14.  
  15. and the output i get is the following
  16.  
  17. \n P15-08-13);\n P15-08-25);\n
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement