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 

Remove everything from last occurence

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


Joined: 10 Feb 2012
Posts: 9

PostPosted: Tue Dec 22, 2015 12:04 am    Post subject: Remove everything from last occurence Reply with quote

Trying my hand at some regex. I'm trying to take a string and remove everything after the last occurrence of and symbol.
I'm using
Code:
regsub {\-.*} $text ""
but it only works if there is only one occurrence of "-" but if text has more than one "-" it removing everything from the first occurrence back. Any help?
I have tried to use string and trim right but that doesn't help either
Code:
string range $text 0 [string last \- $text]-1
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Wed Dec 23, 2015 10:26 am    Post subject: Re: Remove everything from last occurence Reply with quote

From the partyline in a bot of mine:

Code:

[09:18] <mynick> .set text abc-def-ghi-jkl-mno-pqr-stu-vwx-yz
[09:18] <botnick> [14:18:30] #jacky# set text abc-def-ghi-jkl-mno-pqr-stu-vwx-yz
[09:18] <botnick> Ok, set.
[09:18] <mynick> .tcl regsub -start [string last \- $text] {\-.*} $text ""
[09:18] <botnick> Tcl: abc-def-ghi-jkl-mno-pqr-stu-vwx



I hope this helps.
_________________
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
Back to top
View user's profile Send private message
maphex
Voice


Joined: 10 Feb 2012
Posts: 9

PostPosted: Wed Dec 23, 2015 8:24 pm    Post subject: Reply with quote

Will this remove "-" in addition to everything after it?
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Wed Dec 23, 2015 8:58 pm    Post subject: Reply with quote

maphex wrote:
Will this remove "-" in addition to everything after it?


??
That's copy-n-paste, in my post above. It shows you exactly what it does.

Better yet, experiment with it in a script on your own bot. Smile

If it doesn't do what you wanted, then most likely it means that I didn't understand what you actually wanted.

Let us know how it goes.
_________________
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Wed Dec 23, 2015 9:00 pm    Post subject: Reply with quote

maphex wrote:
Will this remove "-" in addition to everything after it?


Are you familiar with using the
.tcl
command in the partyline?

If not, perhaps what I put in my post is not something you instantly recognize, and you need to look that up and get familiar with it. It is very handy, at times.
_________________
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
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