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.
Help for those learning Tcl or writing their own scripts.
arfer
Master
Posts: 436 Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK
Post
by arfer » Sun Mar 08, 2009 3:18 pm
I want to use a single regsub command to colourise text that is inside parenthesis without colourising the parenthesis themselves.
The following would additionally colourise the parenthesis
Code: Select all
set txt "this is a test (hopefully). We'll see"
set txt [regsub -all -- {\([^\)]+\)} $txt "\00314&\003"]
The following would work but is two regsub commands
Code: Select all
set txt "this is a test (hopefully). We'll see"
set txt [regsub -all -- {\(} $txt "(\00314"]
set txt [regsub -all -- {\)} $txt "\003)"]
Is there any regsub syntax that would accomplish my needs?
I must have had nothing to do
tsukeh
Voice
Posts: 31 Joined: Thu Jan 20, 2005 6:22 am
Post
by tsukeh » Sun Mar 08, 2009 3:55 pm
Code: Select all
set txt "this is a test (hopefully). We'll see"
set txt [regsub -all -- {(.*)\(([^)]*)\)(.*)} $txt "\\1(\00314\\2\003)\\3"]
speechles
Revered One
Posts: 1398 Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)
Post
by speechles » Sun Mar 08, 2009 4:05 pm
<speechles> .tcl set txt "this is a test (hopefully). We'll (see) what happens (here)"
<sp33chy> Tcl: this is a test (hopefully). We'll (see) what happens (here)
<speechles> .tcl set txt [regsub -all -- {\((.*?)\)} $txt "\(\00309\\1\003\)"]
<sp33chy> Tcl: this is a test (hopefully ). We'll (see ) what happens (here )
arfer
Master
Posts: 436 Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK
Post
by arfer » Sun Mar 08, 2009 4:24 pm
Ah OK, thanks a lot. I get the gist of it now.
I'm going to try just this. Should be OK I expect (now I've seen what isn't in the manual)
Code: Select all
set txt "this is a test (hopefully). We'll see"
set txt [regsub -all -- {\(([^)]*)\)} $txt "(\00314\\1\003)"]
Hmm, I just saw your post speechless, perhaps this then
Code: Select all
set txt "this is a test (hopefully). We'll see"
set txt [regsub -all -- {\(([^)]*?)\)} $txt "(\00314\\1\003)"]
Anyway. Thanks guys. I can have a play now I know about these replacement functions.
I must have had nothing to do