简体   繁体   中英

Convert Zalgo Text to Plain text

So I have some zalgo text:

Ḩ̡̤̜̩̜̝̉é̪̟̜̗̣̔̊̋̈̅ll̪̟̣̗̣̗̜̜̇̌̋̔̍̉̃̌̏̄̔ọ̘̥̗̇̂̒

and I'm trying to turn that into

Hello

Using python3.6, the function I'm using to convert text to zalgo is

def zalgo(text):
    return ''.join([v,v+''.join(choice(list(map(chr,range(768,815))))for i in range(int(normalvariate(10,5))))][v.isalpha()]for v in text)

Taken from a code-golf question.

What I'm trying to do is get the string back in python3.6 so the example would return Hello

You mayfilter the alphabets/digits from your string using str.isalnum (or str.isalpha for only alphabets) and join it back as:

>>> my_str = 'Ḩ̡̤̜̩̜̝̉é̪̟̜̗̣̔̊̋̈̅ll̪̟̣̗̣̗̜̜̇̌̋̔̍̉̃̌̏̄̔ọ̘̥̗̇̂̒'


>>> ''.join(filter(str.isalnum, my_str))
'Hello'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM