| View previous topic :: View next topic |
| Author |
Message |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Sun Mar 08, 2009 3:18 pm Post subject: regsub syntax |
|
|
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: |
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: |
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 |
|
| Back to top |
|
 |
tsukeh Voice
Joined: 20 Jan 2005 Posts: 31
|
Posted: Sun Mar 08, 2009 3:55 pm Post subject: |
|
|
| Code: |
set txt "this is a test (hopefully). We'll see"
set txt [regsub -all -- {(.*)\(([^)]*)\)(.*)} $txt "\\1(\00314\\2\003)\\3"]
|
|
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sun Mar 08, 2009 4:05 pm Post subject: |
|
|
| Quote: | <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) |
_________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Sun Mar 08, 2009 4:24 pm Post subject: |
|
|
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: |
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: |
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 |
|
| Back to top |
|
 |
|