就像我有一个字符串变量,其值在下面给出
string_value = 'hello ' how ' are - you ? and/ nice to % meet # you'
预期结果:
你好,我很高兴认识你
您可以尝试删除所有非文字字符:
string_value = "hello ' how ' are - you ? and/ nice to % meet # you"
output = re.sub(r'\W+', '', string_value)
print(string_value)
print(output)