string map { old1 new1 old2 new2 … } STRING
Hi,
I don't know if the TCL community is the right place to post a Regular-Expression (RG) enhancement, but let me try :-)
problem: howto put MULTIPLE "regsub" statements into ONE single
(probably more efficient) together.
lets start with "string map…"
string map { old1 new1 old2 new2 … } STRING
ONE command is doing MULTIPLE replacement.
I want to do the same with "regsub" BUT with a RG string, proposal:
regsub {…(old1|old2|…)…} STRING {\?1(new1|new2|…)} OUTVAR
"old1" will be replaced with "new1" … etc
example: >>>>>
string="MyName§E other-thing"
regsub {(\w+)§(E|S|U)} $string {\?2(enum|struct|union) \1} OUTVAR
OUTVAR="enum MyName other-thing"
<<<<<<<<<<<<<<
new is the "\?2(…)"
\2 would replace the match-string and "\?2(…)" will use the
index of the match-string and pig-up the idx-replacement from the "(…}"
mfgA feature of [string map] is that the substitutions are defined in pairs, whereas your suggested syntax interferes with the alternatives already defined in regular expressions. I suspect there are more interferences lurking in there, besides the obvious
problem: howto put MULTIPLE "regsub" statements into ONE single
(probably more efficient) together.
regsub -command {(\w+)§[ESU]} $string [list apply [list {match prefix} {
set ch [string index $match end]
string cat [string map {E enum S struct U union} $ch] " " $prefix
}]] OUTVAR
On 02/05/2022 14:04, Schelte wrote:
regsub -command {(\w+)§[ESU]} $string [list apply [list {match prefix} {Of course that can be simplified to:
set ch [string index $match end]
string cat [string map {E enum S struct U union} $ch] " " $prefix >> }]] OUTVAR
regsub -command {(\w+)§([ESU])} $string [list apply [list {match prefix
ch} {
string cat [string map {E enum S struct U union} $ch] " " $prefix
}]] OUTVAR
Schelte
regsub -all {_(\w)} "config_error_text" {\1??}
Hi,
*regsub* and *regexp* are used to apply a *regexpression* on a string.
In difference to *regexp* the *regsub* is used to modify the string.
I have the following problem:
→ I want to modify the string *config_error_text* to *configErrorText*.
this looks like a simple *regsub* job like:
regsub -all {_(\w)} "config_error_text" {\1??}
but as you see I can not uppercase the '\1' to just do the job I want.
I cant even call a *proc* in the *{\1??}* to do an arbitrary post-processing.
mfgIf I remember correctly, Tcl 8.7 does allow you to specify a procedure like that.
Hi,
*regsub* and *regexp* are used to apply a *regexpression* on a string.
In difference to *regexp* the *regsub* is used to modify the string.
I have the following problem:
→ I want to modify the string *config_error_text* to *configErrorText*.
this looks like a simple *regsub* job like:
regsub -all {_(\w)} "config_error_text" {\1??}
but as you see I can not uppercase the '\1' to just do the job I want.
I cant even call a *proc* in the *{\1??}* to do an arbitrary
post-processing.
mfg
this looks like a simple *regsub* job like:
regsub -all {_(\w)} "config_error_text" {\1??}
but as you see I can not uppercase the '\1' to just do the job I want.
I cant even call a *proc* in the *{\1??}* to do an arbitrary post-processing.
mfgIf I remember correctly, Tcl 8.7 does allow you to specify a procedure like that.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 497 |
Nodes: | 16 (2 / 14) |
Uptime: | 13:46:27 |
Calls: | 9,784 |
Calls today: | 3 |
Files: | 13,748 |
Messages: | 6,187,449 |