regex/matchtext question
Klaus Major
klaus at major-k.de
Thu Feb 5 05:50:15 EST 2009
Hi all,
I have a nice matchtext script that extract "placeholders" from a text.
Like everything between "<<" and ">>" or "::" or "{" and "}"
This is the function I use, it#s a little script of Ken Ray (thanks
Ken!)
that I could understand, at least a bit to modify it:-)
## extract placeholder tText,tdelimiter,delimiter2
## tdelimiter = the delimiter of the returned list of placeholders
## derdelimiter2 = the actual "borders" of the placeholders to extract
function platzhalterextrahieren dertext,derdelimiter,derdelimiter2
if derdelimiter = empty then
put TAB into derdelimiter
end if
if derdelimiter2 = empty then
put "::" into derdelimiter2
end if
switch derdelimiter2
case "::"
put "::" into derdelimiter3
break
case "<<"
put ">>" into derdelimiter3
break
case "{"
put "}" into derdelimiter3
break
end switch
repeat
get matchText(dertext,"(?s)" & derdelimiter2 & "(.*?)" &
derdelimiter3,wert)
if it = false then
exit repeat
end if
put derdelimiter2 & wert & derdelimiter3 into neu
put neu & derdelimiter after neueliste
replace neu with empty in dertext
end repeat
delete char -1 of neueliste
return neueliste
end platzhalterextrahieren
This results in a list like:
::Anrede_90001::
::Titel_90001::
::Nachname_90001::
Or:
<<Anrede_90001>>
<<Titel_90001>>
Or:
{Anrede_90001}
{Titel_90001}
You get the picture.
Works fine so far, but now I also wanted to use "[" and "]" and even
"[[" and "]]"
but I cannot get the script to work. I tried to escape these
characters like:
...
case "["
put "\[" into derdelimiter2
put "\]" into derdelimiter3
break
...
I need to replace the german decimal delimiter COMMA with a dot before
I can
finally MERGE the content of the text, and replace it with a COMMA
after the MERGE.
Know what I mean?
But then I get stuck in an endless repeat loop?!
Is this possible at all with matchtext?
Any hints are highly appreciated!
Thanks a lot in advance!
Best
Klaus
--
Klaus Major
klaus at major-k.de
http://www.major-k.de
More information about the use-livecode
mailing list