string = '***All Done***, ***Execution Success 5664 for $**$ files***'
re pattern = ([\w+].*[\$\*\*]\$.*[\w+]|[\w+])
output i'm getting: 'All Done***, ***Execution Success for $**$ files'
预期输出:All Done Execution Success 5664 for $**$ files
应仅获取字母数字字符和$\*\*$
。其余所有应清除。任何帮助,将不胜感激。如果在字符串上找不到$\*\*$
,则它应返回:All Done Execution Success 5664 for files
。
答案 0 :(得分:0)
这似乎适用于您提供的示例(Python 3.6):
import re
strings = [
'***All Done***, ***Execution Success 5664 for $**$ files***',
'Error not ** found. Restore $**$ again **'
]
pattern = "\w+|\$\*\*\$"
cpattern = re.compile(pattern)
for string in strings:
print(" ".join(cpattern.findall(string)))
输出:
All Done Execution Success 5664 for $**$ files Error not found Restore $**$ again