egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

regsub syntax

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Sun Mar 08, 2009 3:18 pm    Post subject: regsub syntax Reply with quote

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
View user's profile Send private message
tsukeh
Voice


Joined: 20 Jan 2005
Posts: 31

PostPosted: Sun Mar 08, 2009 3:55 pm    Post subject: Reply with quote

Code:

set txt "this is a test (hopefully). We'll see"
set txt [regsub -all -- {(.*)\(([^)]*)\)(.*)} $txt "\\1(\00314\\2\003)\\3"]
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Sun Mar 08, 2009 4:05 pm    Post subject: Reply with quote

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
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Sun Mar 08, 2009 4:24 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber