dimanche 30 septembre 2018

Capture between variable string and pattern in lua

I want to get a string between two strings.

texterrors = [[
    <error_no name="1">
    <designator>M18</designator>
    <pin>M18</pin>
    <stamp_name>Con_10p</stamp_name>
    <package_name>M18</package_name>
    <errortype>9</errortype>
    <error_contents></error_contents>
    <pcb_no></pcb_no>
    <feeder_no></feeder_no>
    <pos_x>23735</pos_x>
    <pos_y>9722</pos_y>
    <window>2</window>
    <ng_message>Histogram NG 0%</ng_message>
    <comment>Histogram NG 0%(* *){Con_10p}</comment>
    <ng_image></ng_image>
    </error_no>
    <error_no name="2">
    <designator>M13</designator>
    <pin>M13</pin>
    <stamp_name>Cage_SFP_back</stamp_name>
    <package_name>M13</package_name>
    <errortype>9</errortype>
    <error_contents></error_contents>
    <pcb_no></pcb_no>
    <feeder_no></feeder_no>
    <pos_x>10962</pos_x>
    <pos_y>14090</pos_y>
    <window>64</window>
    <ng_message>Mismatch13%</ng_message>
    <comment>Mismatch13%(-0.14 -0.07){Cage_SFP_back}</comment>
    <ng_image></ng_image>
    </error_no>
]]

I want to capture n strings, each between "<error_no name="i">"and "</error_no>" My code is below, but results is nil for each i

for i = 1, n do
errindex1[i] = '<error_no name='..'"'..i..'"'..'>'
stringg = errindex[i]
texterr[i] = string.match(texterrors,"..stringg..(%a)</error_no>")

How is possible to use variable string like stringg as pattern?

Aucun commentaire:

Enregistrer un commentaire