Regular expressions
Peter M. Brigham
pmbrig at gmail.com
Thu Jul 4 11:08:43 EDT 2013
On Jul 2, 2013, at 1:13 PM, Terry Vogelaar wrote:
> However, I need to do some thinking how I can turn this into a search-and-replace-all style action. I probably need to write a loop where I use offset to find the first "<span", then find the first "</span>", then use matchChunk to see if it matches and to put things in variables, and then change the span tags into something else temporarily to keep the offset function to find the first one over and over again, and if the last one is found, do some cleaning up to get the span tags back into place.
I don't fully understand what you are doing here, but would the following be useful?
function offsets str,container,includeOverlaps
-- returns a comma-delimited list of all the offsets of str in container
-- returns 0 if not found
-- third param is optional:
-- offsets("xx","xxxxxx") returns "1,3,5" not "1,2,3,4,5"
-- ie, by default, overlapping offsets are not counted
-- if you want overlapping offsets then pass "true" in 3rd param
if str is not in container then return 0
if includeOverlaps = empty then put false into includeOverlaps
put empty into offsetList
put 0 into startPoint
repeat
put offset(str,container,startPoint) into thisOffset
if thisOffset = 0 then exit repeat
add thisOffset to startPoint
put startPoint & comma after offsetList
if not includeOverlaps then
add length(str)-1 to startPoint
end if
end repeat
return item 1 to -1 of offsetList -- delete trailing comma
end offsets
-- Peter
Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig
More information about the use-livecode
mailing list