Code: Select all
(define (sacar-td linea)
(set 'alveolos (find-all "(<td)(.*?)(</td>)" linea $0 1))
(map (fn (x) (replace "</?td(.*?)>" x "" 1)) alveolos))
(define (crash-td linea)
(find-all "(<td)(.*?)(</td>)" linea (replace "</?td(.*?)>" $0 "" 1) 1))
(set 'testrow "<tr><td class='kin'>Alpha</td><td>Gamma</td></tr>")
> (sacar-td testrow)
("Alpha" "Gamma")
> (crash-td testrow)
*** glibc detected *** /usr/bin/newlisp: double free or corruption (fasttop): 0x080cc808 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6[0xb7e31a85]
/lib/tls/i686/cmov/libc.so.6(cfree+0x90)[0xb7e354f0]
...
It is the first strange thing.
Second problem -- my repexps works ok only if I replace all "\n" to " " before searching.
Update: accidentaly found solution for the second problem, it is "(?s)" key. Now my "parse-html" function works:
Code: Select all
; Usage (parse-html (get-url "http://www.newlisp.org/downloads/newlisp_manual.html"))
(define (parse-html texto)
(map sacar-table (find-all "(?s)(<table)(.*?)(</table>)" texto $0 1)))
(define (sacar-td linea)
(set 'alveolos (find-all "(<t[dh])(.*?)(</t[dh]>)" linea $0 1))
(map (fn (x) (replace "</?t[dh](.*?)>" x "" 1)) alveolos))
(define (sacar-table linea)
(map sacar-td (find-all "(?s)(<tr)(.*?)(</tr>)" linea $0 1)))