Clear string in Python (remove escape characters)

1

I came across some strings with the following content, eg:

"++++++//texto+++!!!+++//texto++++"

I'm trying to find a method to clear the sentence but I'm not getting success, could anyone help me?

    
asked by anonymous 14.08.2017 / 18:09

1 answer

4

You can use Regex (Regular Expressions) to find such words, here is a short example:

import re

test1 = "31teste123 regex==="
test2 = "++++//jamanta+++de+++//pedra++++"

def formatString(string):
    formatedArray = re.findall('[a-zA-Z]+', string)
    print(" ".join(formatedArray))

formatString(test1)
formatString(test2)

The output would be an array containing the words:

test1 = ['test', 'regex']

test2 = ['manta', 'de', 'stone']

You can try more things on this site: link

    
14.08.2017 / 20:25