I'm making a small python script that should randomly modify the "tens" of the vector values of an svg.
every line of the file i'm editing looks like this:
<path style="fill:#1b170e; stroke:none;" d="M32 0L33 1L32 0M35 0L35 4L36 4L35 0z"/>
so in this case I want to randomly modify : - the 3 of M32 - the 3 of 0L33 - the 3 of 1L32 - etc
my script looks like this at the moment
#opening file
for file in os.listdir(temp_sub_svg):
f1 = open(temp_sub_svg + '/' + file, 'r')
f2 = open(temp_sub_gsvg + '/' + file, 'w')
for line in f1:
#create random values
r1 = str(random.randint(0, 9))
r2 = str(random.randint(0, 9))
#replace values
newline = re.sub(r"{r1}\d\s", r2, line)
f2.write(newline)
f1.close()
f2.close()
I think I've sussed out how to integrate python variables in my regex, but my main problem is that I'm matching too much data. I'd like to match only the first character of each match. yet what I'm matching in this case is :
- "32 "
- "33 "
- "32 "