我有一个在 Python 中似乎无法解决的问题。我有一个模式需要匹配字符数组中的任何字符。如果没有,那就有问题了。所以这里是我的例子:
pattern = "0000 006e 0022 0002 0156 00ac 0016 0016 0016 0041 0016 0041 0016 0041 0016 0016 0016 0041 0016 0041 0016 0041 0016 0041 0016 0041 0016 0041 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0016 0016 0041 0016 0016 0016 " 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0041 0016 0041 0016 0016 0016 0016 0016 0016 0016 0041 06016 05 0010 06016 05010 06
allowedCharacters = "123456789abcdef"
所以我的目标是查看模式是否符合允许的字符。在 C# 中,我执行了以下操作,但我不知道如何在 Python 中完成此操作。
这是我当前的代码。
# Test that there are only valid characters in the pattern.
charPattern = list(pattern)
expression = list("01234567890abcdef")
for currentChar in pattern:
if len(charPattern) - pattern[-1::-1].index("0123456789abcdef") - 1:
self.assertTrue(False, logger.failed("The invalid character: " + currentChar + " was found in the IRCode pattern for: " + ircode))`enter code here`
欢迎任何想法/建议/代码示例。
谢谢。