This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.
For more information, see this announcement post . Click the X in the top right-corner of this box to dismiss this message.
Old posts that have not been replied to for several years.
B
Baerchen
Post
by Baerchen » Wed Sep 26, 2001 4:26 am
Hi,
Is it possible to put 2 different substitutions into one regsub? Say I want to regsub "1" by "one and "2" by "two".
regsub -all 1 $a one a
regsub -all 2 $a two a
does the job.
Is it possible to put that into _one_ regsub ?
stdragon
Owner
Posts: 959 Joined: Sun Sep 23, 2001 8:00 pm
Contact:
Post
by stdragon » Wed Sep 26, 2001 10:25 pm
You could do it with one regsub and a subst. It's probably better to just do 2 regsubs though
set str "this is 1 test of 2 things"
set keys(1) one
set keys(2) two
regsub -all 1|2 $str {${keys(&)}} str
set str [subst $str]
Just make sure your source string doesn't have special characters in it
B
Baerchen
Post
by Baerchen » Fri Sep 28, 2001 3:44 pm
Hmm, thanks a lot.
My intention was to reduce the amount of regsubs by putting them all into one, but as it seems, it doesn't work. Anyway your solution is very interesting from a genral point of view. Thanks !
Baerchen
Petersen
Owner
Posts: 685 Joined: Thu Sep 27, 2001 8:00 pm
Location: Blackpool, UK
Post
by Petersen » Fri Sep 28, 2001 8:08 pm
personally i just like to write a proc for such things
eg
Code: Select all
proc myregsub {a} {
regsub -all 1 $a one a
regsub -all 2 $a two a
return a
}
can then just regsub a string by doing [myregsub $blah] etc