Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

"Ada is PL/I trying to be Smalltalk. -- Codoso diBlini


devel / comp.lang.tcl / Re: regsub replacement question

SubjectAuthor
* regsub replacement questionaotto1968
+- Re: regsub replacement questionAndreas Leitgeb
`* Re: regsub replacement questionRalf Fassel
 `- Re: regsub replacement questionaotto1968

1
regsub replacement question

<utjc0i$2ppn6$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=13565&group=comp.lang.tcl#13565

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: aotto1968@t-online.de (aotto1968)
Newsgroups: comp.lang.tcl
Subject: regsub replacement question
Date: Fri, 22 Mar 2024 08:29:20 +0100
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <utjc0i$2ppn6$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 22 Mar 2024 07:29:22 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2fd11f0120e038d13b09372e89b371f5";
logging-data="2942694"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/DA6EukJDCiIP3TaE+CY4con0w9IpzEKQ="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:yr+eW1M4VZetdPWsta6ZECp2IbE=
Content-Language: en-US
 by: aotto1968 - Fri, 22 Mar 2024 07:29 UTC

Hi,

# I have a question regarding *regsub* and how to accelerate replacement
# let's assume the following code:

set str "aaa123bbb123ccc123ddd123eee123fff123ggg"

# My goal is to eliminate the all "123" except the FIRST one with the restriction
# that between the "123" is *not* a number other then 123
puts [regsub -all {(\d+)([^\d]*)\1} $str {\1\2}]
> aaa123bbbccc123dddeee123fffggg

# → my problem is that always the SECOND "111" is replaced because the replacement itself is *not*
# checked again.

# my solution is a loop
while {[regsub -all {(\d+)([^\d]*)\1} $str {\1\2} str]} ""

# this works but the GOAL is to have ONE *regsub* to get this job done
puts $str
> aaa123bbbcccdddeeefffggg

mfg ao

Re: regsub replacement question

<slrnuvqet0.a0i.avl@logic.at>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=13566&group=comp.lang.tcl#13566

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: avl@logic.at (Andreas Leitgeb)
Newsgroups: comp.lang.tcl
Subject: Re: regsub replacement question
Date: Fri, 22 Mar 2024 08:04:48 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <slrnuvqet0.a0i.avl@logic.at>
References: <utjc0i$2ppn6$1@dont-email.me>
Reply-To: avl@logic.at
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 22 Mar 2024 08:04:48 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e316c1d2f5efbbf6cc3ce9e65768ea35";
logging-data="2958558"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/wyRfZvBIIT7ArM0ZVkFQS"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:zO0dz2BHcG0RN9yaW8GJN75E4fo=
 by: Andreas Leitgeb - Fri, 22 Mar 2024 08:04 UTC

aotto1968 <aotto1968@t-online.de> wrote:
> # I have a question regarding *regsub* and how to accelerate replacement
> # let's assume the following code:
> set str "aaa123bbb123ccc123ddd123eee123fff123ggg"
>
> # My goal is to eliminate the all "123" except the FIRST one with the restriction
> # that between the "123" is *not* a number other then 123
> puts [regsub -all {(\d+)([^\d]*)\1} $str {\1\2}]
> > aaa123bbbccc123dddeee123fffggg
>
> # → my problem is that always the SECOND "111" is replaced because the replacement itself is *not*
> # checked again.

That is correct, after first substitution of "123bbb123" to "123bbb",
then in the remainder it doesn't see the "ccc" wrapped in "123"s, so
cannot eliminate the trailing "123" for "ccc"

> # my solution is a loop
> while {[regsub -all {(\d+)([^\d]*)\1} $str {\1\2} str]} ""

I think this is the way to go, but you might experiment with
removing the "-all" option... Maybe it improves speed, or
maybe it spoils it, I can't predict.

> # this works but the GOAL is to have ONE *regsub* to get this job done
> puts $str
> > aaa123bbbcccdddeeefffggg

Another approach could be to extract the non-"123"s as a list
with regexp (not regsub), and then just re-insert the number:

set num [regexp -inline {\d+} $str];# get the separating number
set list [regexp -inline -all {\D+} $str] ;# \D is like [^\d]
puts [join [linsert $list 1 $num] ""]

(unless you also need to deal with aaa123bbb123ccc456ddd456 where
the first 456 also needs to stay...)

Re: regsub replacement question

<ygav85eedc0.fsf@panther.akutech-local.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=13568&group=comp.lang.tcl#13568

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralfixx@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: regsub replacement question
Date: Fri, 22 Mar 2024 12:05:35 +0100
Lines: 16
Message-ID: <ygav85eedc0.fsf@panther.akutech-local.de>
References: <utjc0i$2ppn6$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net RP5UQQ6kK1DXzyTyoo2J0AkmyKBbYugQGIkkN4jCuC3bP2iBA=
Cancel-Lock: sha1:Zxib+Dkf8W5U57HhoT0U9OfTBRU= sha1:9g4U1R/8E+45HGlCpkvRfoQh/S0= sha256:foceRRjMsUZeLnnnXegjErFSWLRmjxbDpAXXukfwABc=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Fri, 22 Mar 2024 11:05 UTC

* aotto1968 <aotto1968@t-online.de>
| set str "aaa123bbb123ccc123ddd123eee123fff123ggg"
>
| # My goal is to eliminate the all "123" except the FIRST one with the
| # restriction that between the "123" is *not* a number other then 123

If that *really* is the goal, I would simply search for the first "123"
and then [string map] the rest of them to "":

set str "aaa123bbb123ccc123ddd123eee123fff123ggg"
set res [string range $str 0 [string first 123 $str]+2]
append res [string map {123 ""} [string range $str [string first 123 $str ]+3 end]]

I do not completely understand the second part of the restriction, though...

R'

Re: regsub replacement question

<utm5n0$3ho4a$2@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=13570&group=comp.lang.tcl#13570

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: aotto1968@t-online.de (aotto1968)
Newsgroups: comp.lang.tcl
Subject: Re: regsub replacement question
Date: Sat, 23 Mar 2024 10:00:16 +0100
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <utm5n0$3ho4a$2@dont-email.me>
References: <utjc0i$2ppn6$1@dont-email.me>
<ygav85eedc0.fsf@panther.akutech-local.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 23 Mar 2024 09:00:16 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c140175824ff487d82d3d09fa589bf19";
logging-data="3727498"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+kJmJVzHtTwVRPPnkKVaGyU8RszHibSZU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:A1MEz6fooXAO0fLe9yvcl5BiCQ0=
In-Reply-To: <ygav85eedc0.fsf@panther.akutech-local.de>
Content-Language: en-US
 by: aotto1968 - Sat, 23 Mar 2024 09:00 UTC

On 22.03.24 12:05, Ralf Fassel wrote:
> * aotto1968 <aotto1968@t-online.de>
> | set str "aaa123bbb123ccc123ddd123eee123fff123ggg"
>>
> | # My goal is to eliminate the all "123" except the FIRST one with the
> | # restriction that between the "123" is *not* a number other then 123
>
> If that *really* is the goal, I would simply search for the first "123"
> and then [string map] the rest of them to "":
>
> set str "aaa123bbb123ccc123ddd123eee123fff123ggg"
> set res [string range $str 0 [string first 123 $str]+2]
> append res [string map {123 ""} [string range $str [string first 123 $str ]+3 end]]
>
> I do not completely understand the second part of the restriction, though...
>
> R'

as always the real-problem is much more complicated as the easy example above.

My try is to get a solution without recall the *regsub* multiple times. To achieve this
the *regsub* has to re-scan the substitution as part of the "-all" switch. The
*regsub* has with the '-start' switch already implemented the ability to get this done.

The "123" is just an example because this question is a "followup" of the:
https://wiki.tcl-lang.org/page/BUG+%2D+%27string+length%27+count+also+NON+visible+chars
problem.

the "123" is in real a the regular-expression:

\u001b\[[0-9;]*m

and the

regsub -all {(\d+)([^\d]*)\1} $str {\1\2}

is in real:

# erase CTRL->CTRL doublets
while {[regsub -all {(\u001b\[[0-9;]*m)([^\u001b]*)\1} $STR {\1\2} STR]} {
#puts fire0
}

..

The CORE problem of the

while {[regsub -all ...]} ""

is that every loop the entire STR is processed and *not* just the part starting with the *last*
substitution.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor