kimberlyn wrote:up !

Hi,
Glad that you made it!
However, I think it could interest few LiveCoders to have a full working code,
so here is one..
I worked with some datas; the first 3 lines are fine, others not:
Code: Select all
ITEM1,10,3,50,ATK,DFS,SPE,[GOF,30,33,0];
ITEM2,10,3,50,ATK,DFS,SPE,[GOF,30,33,0;TTF,21,33,;JDK,10,20,45];
ITEM3,10,3,50,ATK,DFS,SPE,[GOF,30,33,0;FFG,12,13,];
ITEM4,10,3,50,ATK,DFS,SPE [FFG,12,13,];
ITEM5,10,3,50,ATK,DFS,SPE,[GOF,30,33,0;;FFG,12,13,];
ITEM6,10,3,50,ATK,DFS,SPE,[GOF,30,33,0;]FFG,12,13,];
ITEM7,10,3,50,ATK,DFS,SPE,[];
ITEM8,10,3,50,ATK,DFS,SPE,[GOF,30,33,0,FFG,12,13,];
Code: Select all
local myLog
on mouseup
put empty into myLog
put field "Ftest" into myText
repeat for each line aLine in myText
-- Validate a list of 8 items with a comma separator
-- the last item is enclosed by brackets, end of line is ;
-- and split the line in 2 parts
get "(?x) " & \ # whitespaces ignored in regex
" \A " & \ # beginning of the line
" ( (?: [^,]+,){7} ) " & \ # first 7 non-empty items separated by comma plus capture it
" \[ ( [^\]]+ ] ) " & \ # the eight item enclosed by square brackets plus capture it
" ;\z " # last char of the line is a semi-column
if not matchText( aLine, IT, part1, part2 ) then
myput "Bad1:", aLine
next repeat
end if
-- Validate part1, ie: ITEM3,10,3,50,ATK,DFS,SPE,
get "(?x) " & \ # whitespaces ignored in regex
" \A " & \ # beginning of the line
" [\w]+ , " & \ # 1st item is A-Z or 0-9 chars non-empty
" (?: [\d]+,){3} " & \ # items 2 to 4 are non-empty numbers. do not capture ()
" (?: [\w]+,){3} " & \ # items 5 to 7 are non-empty A-Z chars. do not capture ()
" \z " # end of line
if not matchText( part1, IT ) then
myput "Bad2:", part1
next repeat
end if
-- Validate part2, ie: GOF,30,33,0;FFG,12,13,]
get "(?x) " & \ # whitespaces ignored in regex
" \A " & \ # beginning of the line
"(?: " & \ # 1st block, do not capture ()
" [\w]+ " & \ # 1st item is A-Z or 0-9 chars non-empty
" (?:,[^,;\]]*){3} " & \ # 3 empty or not items, comma separator, do not capture ()
" [;\]] " & \ # ending with a ; or ]
")+ " & \ # end of 1st block: 1 or more times
" \z " # end of line
if not matchText( part2, IT ) then
myput "Bad3:", part2
next repeat
end if
myput "OK 1:", aLine
end repeat
put myLog
end mouseup
on myput p1, p2
put p1 & tab & p2 &cr after myLog
end myput
Regards,
Thierry