一种搜索正则表达式模式的算法

2024-09-27 04:10:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我为在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))

Tags: 文件txt算法container模式单元测试nrfile
1条回答
网友
1楼 · 发布于 2024-09-27 04:10:53

正则表达式中有ł。必须更改Unicode编码或将其删除。 如果这不起作用,检查这个“卡住”的文件,如果他们包含一些奇怪的字符

相关问题 更多 >

    热门问题