Code: Select all
> (find-all "(?<=,)[^,]*(?=,)" ",1,10,,100,1000,")
("1" "10" "")
Code: Select all
("1" "10" "" "100" "1000")
Is it a feature to make programmers use "parse" operator for empty string searching?
Code: Select all
> (find-all "(?<=,)[^,]*(?=,)" ",1,10,,100,1000,")
("1" "10" "")
Code: Select all
("1" "10" "" "100" "1000")
Code: Select all
(find-all "[^,]+" ",1,10,,100,1000," ) => ("1" "10" "100" "1000")
Code: Select all
(parse ",1,10,,100,1000," ",") => ("" "1" "10" "" "100" "1000" "")
Code: Select all
(clean empty? (parse ",1,10,,100,1000," ",")) => ("1" "10" "100" "1000")
Code: Select all
(find-all {(^|(?<=,))("(([^"]|"")*)"|([^",]*))}
{Ten Thousand,10000, 2710 ,,"10,000","It's ""10 Grand"", baby",10K})
Code: Select all
(set 'offset 0)
(while (set 'pos (find {(^|(?<=,))("(([^"]|"")*)"|([^",]*))}
{Ten Thousand,10000, 2710 ,,"10,000","It's ""10 Grand"", baby",10K} 0 offset ))
(push $0 lst -1)
(println "->" (offset $0) "<-")
(inc offset (+ 1 (length $0)))
)
lst => ("Ten Thousand" "10000" " 2710 " "" "\"10,000\"" "\"It's \"\"10 Grand\"\", baby\"" "10K")
(lst -2) => "\"It's \"\"10 Grand\"\", baby\""
Code: Select all
(set 'offset 0 'lst '())
(while (set 'pos (find {(^|(?<=,))("(([^"]|"")*)"|([^",]*))}
{Ten Thousand,10000, 2710 ,,"10,000","It's ""10 Grand"", baby",10K} 0 offset ))
(if (and lst (= (last lst) $0 ""))
(inc offset)
(begin
(set 'offset (+ offset (length $0)))
(push $0 lst -1))))
Code: Select all
{Ten Thousand,10000, 2710 ,,,,,,,"10,000","It's ""10 Grand"", baby",10K}
Yep, I have made an error: I did not took into account difference between starting search position and actual offset of the found item:Lutz wrote:Unfortunately this strategy will swallow legitimate empty strings
Code: Select all
(set 'offset 0 'lst '())
(while (set 'offset (find {(^|(?<=,))("(([^"]|"")*)"|([^",]*))}
{Ten Thousand,10000, 2710 ,,,,,,,"10,000","It's ""10 Grand"", baby",10K} 0 offset))
(set 'offset (+ offset (length $0)))
(if (and lst (= (list offset $0) (last lst)))
(inc offset)
(push (list offset $0) lst -1)))
(silent
(println "--- Found: " (length lst) " ---")
(map println lst))
Code: Select all
(set 'offset 0 'lastOffset 0 'lst '())
(while (set 'offset (find {(^|(?<=,))("(([^"]|"")*)"|([^",]*))}
{Ten Thousand,10000, 2710 ,,,,,,,"10,000","It's ""10 Grand"", baby",10K} 0 offset))
(set 'offset (+ offset (length $0)))
(if (= offset lastOffset)
(inc offset)
(begin
(set 'lastOffset offset)
(push $0 lst -1))))
Code: Select all
(find-all "((?<=FILE:)[0-9]*)|(sample.gif)" "FILE:sample.gif")