Hi,
my code
# @cartouche
while {[regexp -indices {@cartouche[^@]+@smallexample(.*?)@end smallexample[^@]+@end cartouche} $txt allI valI]} {
Am 26.06.22 um 21:05 schrieb aotto1968:
Hi,
my code
# @cartoucheI haven't checked the details, but your RE mixes greedy (+) and
while {[regexp -indices {@cartouche[^@]+@smallexample(.*?)@end smallexample[^@]+@end cartouche} $txt allI valI]} {
non-greedy (.*?) quantifiers. AFAIK, this can lead to hard to understand behaviour. Quote from the manpage: https://www.tcl.tk/man/tcl8.6/TclCmd/re_syntax.html
"The matching rules for REs containing both normal and non-greedy quantifiers have changed since early beta-test versions of this package. (The new rules are much simpler and cleaner, but do not work as hard at guessing the user's real intentions.) "
Having that said, you could also look into packages that facilitate
parsing (lexers). There used to be fickle/fcl (that was used by
tcldoc; I am writing in past-tense, because a quick web search did
not show their current homes).
[1] https://xkcd.com/208/
One could argue that Tcl 9 should migrate to PCRE and drop Spencer's RE, which is also badly maintained. Someone with more moment than me could
write a TIP about it ;)
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 497 |
Nodes: | 16 (2 / 14) |
Uptime: | 67:25:36 |
Calls: | 9,766 |
Calls today: | 7 |
Files: | 13,745 |
Messages: | 6,185,945 |