我为算法创建了单元测试以在 txt 文件中搜索正则表达式模式。在分析这个正则表达式的过程中,它被一些文件卡住了:
(nr|numer|[fj]ak[^\r\n]{1,3}ura)\s((?!kas|par|rej|kl\.|kont|te[lł]|klien|zlece|trans|zam|dz|pkwiu|wydr))?(?!rachunk|lic)(.*\n){5}`
测试:
def testNIPMass(self):
#mypath="E:\\Skrypt\\txts\\1"
mypath="C:\\Users\\lataman\\Documents\\OCR\\PyVer\\skrypt\\txts\\1"
container=schemeContainer.createObject("PL")
for f in listdir(mypath):
file = join(mypath,f)
if isfile(file):
tArray=utilities.fopen(file).split('\n')
NIPclient=container.seekPattern("InvoiceNumber", tArray, returnPatterns=True)
print("File: "+f+"\nInvoiceNumber: "+str(NIPclient))
请您参考如下方法:
您在正则表达式中有 ł。您必须更改 Unicode 编码或将其删除。 如果这不起作用,请检查此“卡住”文件是否包含一些奇怪的字符。
