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.
maphex
Voice
Posts: 9 Joined: Fri Feb 10, 2012 5:06 pm
Post
by maphex » Tue Dec 22, 2015 12:04 am
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
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: Select all
string range $text 0 [string last \- $text]-1
willyw
Revered One
Posts: 1205 Joined: Thu Jan 15, 2009 12:55 am
Post
by willyw » Wed Dec 23, 2015 10:26 am
From the partyline in a bot of mine:
Code: Select all
[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 !
maphex
Voice
Posts: 9 Joined: Fri Feb 10, 2012 5:06 pm
Post
by maphex » Wed Dec 23, 2015 8:24 pm
Will this remove "-" in addition to everything after it?
willyw
Revered One
Posts: 1205 Joined: Thu Jan 15, 2009 12:55 am
Post
by willyw » Wed Dec 23, 2015 8:58 pm
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.
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 !
willyw
Revered One
Posts: 1205 Joined: Thu Jan 15, 2009 12:55 am
Post
by willyw » Wed Dec 23, 2015 9:00 pm
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 !