If I need to do regex replacement 27000 times, how to shorten it?

Joined
Dec 19, 2024
Messages
10
Reaction score
0
If I need to do regex replacement 27000 times with different pattern search and replacement, how to shorten it?
Code:
import re
from _Arm64HexDatabase import *

handle_file1 = open("example1", "rb")
hex_read = handle_file1.read()
handle_file1.close()

hfile3 = open("result1.txt", "a")

hex_read = re.sub(hex_suba64w0w0w0, hex_mova64w0c0, hex_read)
...
hex_read = re.sub(hex_suba64w31w31w31, hex_mova64w31c0, hex_read)

hex_read = re.sub(hex_suba64x0x0x0, hex_mova64x0c0, hex_read)
...
hex_read = re.sub(hex_suba64x31x31x31, hex_mova64x31c0, hex_read)

hex_read = re.sub(hex_suba64w0w0c0, hex_mova64w0w0, hex_read)
...
hex_read = re.sub(hex_suba64w31w31c0, hex_mova64w31w31, hex_read)

hex_read = re.sub(hex_suba64x0x0c0, hex_mova64x0x0, hex_read)
...
hex_read = re.sub(hex_suba64x31x31c0, hex_mova64x31x31, hex_read)

hex_read = re.sub(hex_suba64w0w0wzr, hex_mova64w0w0, hex_read)
...
hex_read = re.sub(hex_suba64w31w31wzr, hex_mova64w31w31, hex_read)

hex_read = re.sub(hex_suba64x0x0xzr, hex_mova64x0x0, hex_read)
...
hex_read = re.sub(hex_suba64x31x31xzr, hex_mova64x31x31, hex_read)

hex_read = re.sub(hex_adda64w0w0c0, hex_mova64w0w0, hex_read)
...
hex_read = re.sub(hex_adda64w31w31c0, hex_mova64w31w31, hex_read)

hex_read = re.sub(hex_adda64x0x0c0, hex_mova64x0x0, hex_read)
...
hex_read = re.sub(hex_adda64x31x31c0, hex_mova64x31x31, hex_read)

hex_read = re.sub(hex_adda64w0w0wzr, hex_mova64w0w0, hex_read)
...
hex_read = re.sub(hex_adda64w31w31wzr, hex_mova64w31w31, hex_read)

hex_read = re.sub(hex_adda64x0x0xzr, hex_mova64x0x0, hex_read)
...
hex_read = re.sub(hex_adda64x31x31xzr, hex_mova64x31x31, hex_read)

The re.sub need to be done about 27000 times with different first and second argument

I wrote it 27000 times (27000 lines) in python

How to shorten it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,083
Messages
2,570,591
Members
47,212
Latest member
RobynWiley

Latest Threads

Top