I would like to be able to do in Python what is so simple in Perl:
The closest I come is
I dont care if a solution to the problem is non-compliant with unicode. All my scripts and filenames are straight ascii anyway, plus I can use either v 3.7 or v 2.7.15
$name = $filename_in_loop_input $name =~ s/ epub//ig; $name =~ s/ pdf//ig; $name =~ s/\)$//ig; $name =~ s/\s$//ig; $name =~ s/\s\s/ /ig; $name =~ s/(\-\w)/ $1/ig; # -x to - x $name =~ s/(\w\-)/$1 /ig; # x- to x - $name =~ s/\./ /g;But I seem to be running into problems.
The closest I come is
import re fh = open('file.txt', 'rt') for line in fh.readlines(): line.strip() a = line a = (re.sub('(?i)we','YOU',line)) # sub1 a = (re.sub('(?i)lose','WIN',line)) # sub2 print(a) fh.close()This works but only with the regex at sub2. Sub1 is ignored. I need something that will modify the variable of a file being parsed, in as simple a form as possible. The regex module seems promisingly close to PCRE for the complex stuff, but for now need something simple but effective for *simply* adding and modifying large amounts of regex substitutions. Some of my perl scripts have dozens to hundreds so that dict methods of doing this are unappealing, especially as they heavily rely on regexes.
I dont care if a solution to the problem is non-compliant with unicode. All my scripts and filenames are straight ascii anyway, plus I can use either v 3.7 or v 2.7.15