Hi, sorry I was offline for so long. But many thanks for the profusion of replies.
Richmond, interesting. I was a bit surprised when I read:
if SEMAPHORE contains "START" then
put char 1 of URTEXT after line LYNE of fld "fXTRACT"
end if
But that was because you were "copying" the text between (and including) the brackets [ and ] and I was looking for the opposite, the text NOT in the brackets. But that's down to me since when I went back and re-read my message I was not clear at all.
Thiery, thank you so much for the solutions in regex. I should really try and invest some time in figuring out how it works since it is handy and powerful looking. I tried both your solutions and they both worked. Which does beg the question, what is the difference?
first ex: "(?x) (\[ [^\] ]+ ] )"
second ex: "(\[[^\]]+])"
I do have a couple of questions
1. Does the "(?x)" mean match the second (group) one or more times?
2. does the second group mean find the literal character "[" followed by some stuff "[^" followed by another literal character "]" one or more times?
Still looks greek to me. Here's my code below, includes my solution in LC plus the 2 regex solutions. Typical in/out was:
in: Taiwan[19]
out: Taiwan
The bit about the tcounter is just to organize a single column of input into 2 columns in the output ie. if even lines follow by cr, if odd lines follow by tab
Code: Select all
on mouseUp pButtonNumber
put url ("file:" & specialfolderpath("desktop") & "/LC Drop File/capital.txt") into tText
-- convert text file to a 2 column tab delimited list
put 0 into tcounter
repeat for each line tline in tText
-- check for bracketed text like [this] in the string, and cut
-- put replacetext(tline, "(?x) (\[ [^\] ]+ ] )", empty) into tline
put replacetext(tline, "(\[[^\]]+])", empty) into tline
-- put offset ("[", tline) into tStart
-- if tStart > 0 then
-- put offset ("]", tline) into tEnd
-- if tEnd > tStart then
-- put char 1 to tStart-1 of tline into tFirst
-- put char tEnd + 1 to the number of chars of tline of tline into tLast
-- put tFirst & tLast into tline
-- end if
-- end if
add 1 to tcounter
if tcounter mod 2 is 0 then -- even number
put tline & return after tList
else -- odd number
put tline & tab after tList
end if
end repeat
set the dgText of group "DataGrid 1" to tList
end mouseUp
PS Thiery, any suggestions for brushing up on regex?
Cheers and many thanks everyone,
Mark