繁体   English   中英

寻找正则表达式以匹配以下内容

[英]Looking for a regular expression to match following

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

这似乎适用于您提供的示例(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 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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