我有一些字符串的for循环,我希望从这些字符串中删除_win64|_win32|_x64|_x86
和.dll
中的任何一个以及所有小写字母
from re import match, sub, compile, escape, IGNORECASE, MULTILINE
filename = filename_without_extension.lower()
print("filename {}".format(filename))
pattern = compile("^(?:.*)(_win64|_win32|_x64|_x86)\.dll$", IGNORECASE|MULTILINE)
for dll in p.memory_maps():
file = dll.path.lower().rsplit('\\', 1)[1]
if not file.endswith(".dll") and not file.endswith(".DLL"): continue # TODO: Remove
print("file: {}".format(file))
print("pattern: {}".format(pattern.sub("", file)))
if pattern.sub("", file).endswith(filename): return AddonStatus.LOADED
为什么在正则表达式中这么难?
编辑:file
变量内的一些示例字符串:
test.dll
test_win32.DLL
test_WIN64.dLL
test_X86.dll
test_x64.DLL
答案 0 :(得分:1)
lst= ['test.dll',
'test_win32.DLL',
'test_WIN64.dLL',
'test_X86.dll',
'test_x64.DLL']
import re
to_remove = ('_win64', '_win32', '_x64', '_x86')
r = re.compile(r'({})\.dll$'.format('|'.join(map(re.escape, to_remove))), flags=re.I)
for l in lst:
print(r.sub(r'', l).lower().rstrip('.dll'))
这将删除所有后缀+ .dll:
test
test
test
test
test
答案 1 :(得分:0)
现在我要使用
messageSource.setBasename("file:/path/to/file/messages");
如果您有更好的解决方案,请随时分享:)