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.

Regex output

Help for those learning Tcl or writing their own scripts.
Post Reply
X
X-Ception
Voice
Posts: 37
Joined: Fri May 20, 2005 3:12 am
Location: Earth
Contact:

Regex output

Post by X-Ception »

Hi,
i have a script pre made that relays information from one channel to another, but i require the outputted information to be pre regex formatted. So that its put in normal at channel A and the output in channel B is regex.

anyone got any ideas ? been looking for a while cant seem to get it right :(
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

How is an output supposed to become a regex? Either a string is an regular expression, or it just a string.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
X
X-Ception
Voice
Posts: 37
Joined: Fri May 20, 2005 3:12 am
Location: Earth
Contact:

Post by X-Ception »

De Kus wrote:How is an output supposed to become a regex? Either a string is an regular expression, or it just a string.
well its just url conversion so im guessing just a string im very unfamiliar with regex to be honest ( working on that tho ) an example output would be

Channel A relays goto irc.somewhere.net
Channel B outputs goto irc\.somwehere\.net

least i think thats right again im still reading up on regex :/

from my knowledge it needs to work the same way unrealircd's does
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

what about string map?
[string map {. \\.} $string]
should be just fine
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
X
X-Ception
Voice
Posts: 37
Joined: Fri May 20, 2005 3:12 am
Location: Earth
Contact:

Post by X-Ception »

De Kus wrote:what about string map?
[string map {. \\.} $string]
should be just fine
would you mind giving an example on usage ? as i say its new to me :/ dont want to screw it up
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

X-Ception wrote:would you mind giving an example on usage ? as i say its new to me :/ dont want to screw it up
open up your eyes, I gave you an example :P. Be more detailed to get a more detailed example :P.

Code: Select all

% string map {. \\.} "goto irc.somewhere.net"
goto irc\.somewhere\.net
You can try it on your own tcl shell if you dont trust me :D. Just a little note, when you use "" instead of {} you will need to use ". \\\\." :P.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
X
X-Ception
Voice
Posts: 37
Joined: Fri May 20, 2005 3:12 am
Location: Earth
Contact:

Post by X-Ception »

De Kus wrote:
X-Ception wrote:would you mind giving an example on usage ? as i say its new to me :/ dont want to screw it up
open up your eyes, I gave you an example :P. Be more detailed to get a more detailed example :P.

Code: Select all

% string map {. \\.} "goto irc.somewhere.net"
goto irc\.somewhere\.net
You can try it on your own tcl shell if you dont trust me :D. Just a little note, when you use "" instead of {} you will need to use ". \\\\." :P.
lol thank you and aplogies :/

appreciated i'll have a play now.

and no not that i dont trust you or anything like that at all more a case of its very new to me and im not exactly the greatest scripter going as is, so do just need longer to run these things thru my brain.
X
X-Ception
Voice
Posts: 37
Joined: Fri May 20, 2005 3:12 am
Location: Earth
Contact:

Post by X-Ception »

Thank you, works perfectly now. :)
X
X-Ception
Voice
Posts: 37
Joined: Fri May 20, 2005 3:12 am
Location: Earth
Contact:

Post by X-Ception »

Ok i have one more tiny issue, ive got everything working perfect till a space comes into play so far i have :

Code: Select all

    putserv "PRIVMSG #channel :  [string map {. \\. : \\: / \\/ exe \exe$ * \\* bat \bat$ jpg \jpg$ mpg \mpg$}  $text]"
which works fine till a space comes into it so then it only echoes the first char, normally without replacement i would use

Code: Select all

[lrange $text 0 end]
to echo the entire sentance, sadly this doesnt work and still picks up the first char :( any ideas ?
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

do you want to strip leading and trailing spaces?!
then you should have scrolled down the string manual some more, string trim will delete them.
just: [string trim $text]

PS: dont use list commands on strings. list commands are intented to be used with proper lists only (made by split, list or lappend).
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
X
X-Ception
Voice
Posts: 37
Joined: Fri May 20, 2005 3:12 am
Location: Earth
Contact:

Post by X-Ception »

De Kus wrote:do you want to strip leading and trailing spaces?!
then you should have scrolled down the string manual some more, string trim will delete them.
just: [string trim $text]

PS: dont use list commands on strings. list commands are intented to be used with proper lists only (made by split, list or lappend).
Yep thats ok, but still only outs puts the first word in the relay :/ i thought parhaps [string wordstart $text wordend ] might do it but alas still only one word and a fair few hundred rehases trying to rack my braina round it
User avatar
Sir_Fz
Revered One
Posts: 3793
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

X-Ception wrote:... i thought parhaps [string wordstart $text wordend ] ...
You mean:

Code: Select all

string range $text 0 end
X
X-Ception
Voice
Posts: 37
Joined: Fri May 20, 2005 3:12 am
Location: Earth
Contact:

Post by X-Ception »

well that's what i was looking at too, but i think ive goofed up somewhere else int he script :| could it be possibly this bit since it was mentioned earlier as being incorrect

Code: Select all

  set text [lindex [split $text " "] 0]
X
X-Ception
Voice
Posts: 37
Joined: Fri May 20, 2005 3:12 am
Location: Earth
Contact:

Post by X-Ception »

and the corrected line for relay is:

Code: Select all

    putserv "PRIVMSG <chan> : \037Text:\037 [string map {. \\. : \\: / \\/ exe \exe$ * \\* bat \bat$ jpg \jpg$ mpg \mpg$} [string range $text 0 end] ]"
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

X-Ception wrote:well that's what i was looking at too, but i think ive goofed up somewhere else int he script :| could it be possibly this bit since it was mentioned earlier as being incorrect

Code: Select all

  set text [lindex [split $text " "] 0]
this line is the reason for your "one word" problem.
btw... after that line $text is a string again. drop that lindex thing. oh, btw. if you want to elimiate multiple white spaces... this wont be enough :D. that might be the first time you could consider using regsub :D.
ex.: regsub -all {\s+} $text { } text
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Post Reply