Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from re import sub
- # var
- # re_match = r":[a-z]+"
- re_match = r"[a-z]+\n[a-z]+"
- re_replace = "WOWOW"
- # charge les données dans une variable
- fp = Path(".").parent.joinpath("test.dat").resolve()
- with fp.open() as f:
- data = f.read()
- # match multiligne
- print(sub(re_match, re_replace, data))
- # mon fichier test.dat contient
- # images/:id/huge
- # images/:id/small
- # documents/:id/main
- # documents/:id/supplementary
- # ce qui est lu dans la var "data"
- # images/:id/huge\nimages/:id/small\ndocuments/:id/main\ndocuments/:id/supplementary\n
- # ce qui sort après sub
- # images/:id/WOWOW/:id/WOWOW/:id/WOWOW/:id/supplementary
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement