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.

regsub $nick escape | char?

Old posts that have not been replied to for several years.
Locked
d
doze

regsub $nick escape | char?

Post by doze »

I got a script that removes users nick from a string with a certain trigger. The problem is that when the nick has | character in it, regsub removes the nick but leaves the | character.. Can I somehow go around this..?

the regsub I have is:

regsub -all -nocase "$nick" $nick_string "" nick_string
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Because regsub uses regular expressions for it's matching mechanism,
the | is interpretted as "OR" by regsub.... these need to be escaped if you mean | literally...

ie.

Code: Select all

regsub -all "\\|" $nick "\\\|" nick2
regsub -all "$nick2" $nickstring "" nickstring
However, this can obviously avoided by using string map, as it
does not use regular expressions for its matching mechanism...
ie.

Code: Select all

set nickstring [string map "$nick {}" $nickstring]
d
doze

Post by doze »

Thank you for your quick reply, works like a charm now! :D (used string map)
Locked