• Parser Help
    2 replies, posted
I am trying to parse rules from my website into a menu but the parsing just wont work correctly. It used to work previously (around a year ago). It doesnt want to return anything. Code for the parser: function testrules(body, len, headers, code)     rules.Rules = {}     local order = 0     for section, sectionStr in string.gmatch(body, "class=\"mycode_b\">(.-):?</span>(.-)</li></ul>") do         rules.Rules[section] = {Order = order}         for rule in string.gmatch(sectionStr, "<li>(.-)<br />") do             table.insert(rules.Rules[section], rule)             PrintTable( rules.Rules )         end         order = order + 1     end end http.Fetch( "website", testrules, function() end ) Code from the website for one section: <span style="color: #A9A9A9;" class="mycode_color"><span style="font-size: x-large;" class="mycode_size"><span style="text-decoration: underline;" class="mycode_u"><span style="font-weight: bold;" class="mycode_b">Test Title1::</span></span></span></span><ul class="mycode_list"><li>Test Rule 1.<br /> </li> <li>Test Rule 2.<br /> </li> <li>Test Rule 3.<br /> </li> <li>Test Rule 4.<br /> </li> <li>Test Rule 5.<br /> </li> <li>Test Rule 6.<br /> </li> </ul> <br /> I can do function testrules(body, len, headers, code) rules.Rules = {} local order = 0 for section, sectionStr in string.gmatch( body, "class=\"mycode_b\">(.-)</span>" ) do order = order + 1 print( order .. " : " .. section ) end end http.Fetch( "website", testrules, function() end ) and it returns 1 : Test Title1: 2 : Test Title2: 3 : Test Title3: 4 : Test Title4:
its a mistake with your regular expression that cant match. I made it work like this;     for section, sectionStr in string.gmatch( str, "<li>(.-)<br" ) do         print(section )     end heres the output: Test Rule 1. Test Rule 2. Test Rule 3. Test Rule 4. Test Rule 5. Test Rule 6.
It worked, thanks.
Sorry, you need to Log In to post a reply to this thread.