Feb-22-2017, 02:57 PM
That is strange, I simply used a for loop and made an average, like so;
Anyhow, do you know how to fix the pattern in order to accept non-alphanumeric chars?
#!/usr/bin/python3 import re import time pattern = re.compile(r'[\w ]?\|BS\|') buffer = "it |BS||BS||BS|this is one|BS||BS||BS|an example" #|BS| as in Backspace test=time.time() for x in range(0,100000): while re.search("\|BS\|", buffer): array = list(buffer) for m in re.finditer("\|BS\|", buffer): del array[m.start():m.end()] if m.start()-1 >= 0: del array[m.start()-1] buffer = ''.join(array) break print(buffer) print((time.time()-test)/100000)I though it might be python 3 vs 2, altough with the example you provided I get similar results as what you just showed..
Anyhow, do you know how to fix the pattern in order to accept non-alphanumeric chars?