| View previous topic :: View next topic |
| Author |
Message |
maphex Voice
Joined: 10 Feb 2012 Posts: 9
|
Posted: Tue Dec 22, 2015 12:04 am Post subject: Remove everything from last occurence |
|
|
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 |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Wed Dec 23, 2015 10:26 am Post subject: Re: Remove everything from last occurence |
|
|
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 |
|
 |
maphex Voice
Joined: 10 Feb 2012 Posts: 9
|
Posted: Wed Dec 23, 2015 8:24 pm Post subject: |
|
|
| Will this remove "-" in addition to everything after it? |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Wed Dec 23, 2015 8:58 pm Post subject: |
|
|
| 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 ! |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Wed Dec 23, 2015 9:00 pm Post subject: |
|
|
| 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 |
|
 |
|