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.

Inverting regsub's functions

Help for those learning Tcl or writing their own scripts.
Post Reply
F
Fill
Halfop
Posts: 80
Joined: Sun Jan 18, 2009 6:08 pm

Inverting regsub's functions

Post by Fill »

Hey guys,

I'm using regsub to check if a variable matches a regular expression and if it does, regsub will replace the part that matches by what I want and assign that to a new variable

however, I wanted to make the opposite. I want regsub to assign the part of the variable that matched the regular expression to a variable. How can I do this?
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

Use Regexp

Code: Select all

set txt SomeTextHere
regexp -all {Text} $txt new
$new will contain the match, in this case "Text"
Elen sila lúmenn' omentielvo
F
Fill
Halfop
Posts: 80
Joined: Sun Jan 18, 2009 6:08 pm

Post by Fill »

ahmmm, nice, thanks a lot!
Post Reply