Hi,
my code
# @cartouche
while {[regexp -indices {@cartouche[^@]+@smallexample(.*?)@end
smallexample[^@]+@end cartouche} $txt allI valI]} {
set val [string trim [string range $txt {*}$valI]]
set val [string map { \\@\{ @\{ } $val ]
set txt [string replace $txt {*}$allI "~~~~~\n$val\n~~~~~" ]
}
with data from:
@cartouche
@smallexample
# file: quote.cfg
quote = "Criticism may not be agreeable, but it is necessary."
" It fulfils the same function as pain in the human"
" body. It calls attention to an unhealthy state of"
" things.\n"
"\t--Winston Churchill";
@end smallexample
@end cartouche
@cartouche
@smallexample
# file: test.cfg
info: @{
name = "Winston Churchill";
@@include "quote.cfg"
country = "UK";
@};
@end smallexample
@end cartouche
create the *false* match:
~~~~~
# file: quote.cfg
quote = "Criticism may not be agreeable, but it is necessary."
" It fulfils the same function as pain in the human"
" body. It calls attention to an unhealthy state of"
" things.\n"
"\t--Winston Churchill";
@end smallexample
@end cartouche
@cartouche
@smallexample
# file: test.cfg
info: @{
name = "Winston Churchill";
@@include "quote.cfg"
country = "UK";
@};
~~~~~
because of error in ".*?" → should find the *smalles* match.
the *good* solution would be:
~~~~~
# file: quote.cfg
quote = "Criticism may not be agreeable, but it is necessary."
" It fulfils the same function as pain in the human"
" body. It calls attention to an unhealthy state of"
" things.\n"
"\t--Winston Churchill";
~~~~~
~~~~~
# file: test.cfg
info: @{
name = "Winston Churchill";
@@include "quote.cfg"
country = "UK";
@};
~~~~~
example online:
https://regex101.com/r/AWkpiL/1
mfg