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 

regexp issue

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


Joined: 11 Feb 2005
Posts: 323
Location: *HeLL*

PostPosted: Sat Sep 15, 2007 12:46 am    Post subject: regexp issue Reply with quote

Hi

Can you tell me how can I regexp a number which contains certain things before and after for ex:


I want to look for "3" but look for 3 only when 3 has a number before it and an alphabet after it and turn 3 into THREE.

like this

11.6 3 test --> then turn 3 into Three

Turn Number three into Alphabet Three

but

if it's number 3 number then return
or if it's alphabet 3 alphabet return

Thanks
iamdeath
_________________
|AmDeAtH @ Undernet


Death is only the *Beginning*...
Back to top
View user's profile Send private message Visit poster's website
awyeah
Revered One


Joined: 26 Apr 2004
Posts: 1580
Location: Switzerland

PostPosted: Sat Sep 15, 2007 9:07 am    Post subject: Re: regexp issue Reply with quote

iamdeath wrote:
Hi
like this:

11.6 3 test --> then turn 3 into Three


To match this you can use this:
Code:

#if $text is the string: "11.6 3 test"

if {[regexp {^(([0-9.]{3,})|([0-9]{1,}))(\x20)(3)(\x20)([a-z]{1,})$} $text]} {

#for substitution you can use regsub or string map
#or you can do it this way:

set text [split $text]
set text [lindex $text 0] Three [lindex $text 2]

_________________
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
iamdeath
Master


Joined: 11 Feb 2005
Posts: 323
Location: *HeLL*

PostPosted: Sat Sep 15, 2007 10:57 am    Post subject: Reply with quote

Thanks for your reply awyeah but I dont think that will slve my problem ok let me tell you again, currently I am using this:

Code:
regsub -all { 3 } $text " Three Runs " text


That will make " 3 " into " Three Runs ", but I want some changes like:

If 3 has numbers before it and alphabet after it then make that " 3 " into " Three Runs "

For ex:

Code:
over 18.1 3 fuller
over 19.4 3 This is a test


I want that " 3 " to be turned into Three Runs. So it will look like:

Code:
over 18.1 Three Runs fuller
over 19.4 Three Runs This is a test


Thanks
_________________
|AmDeAtH @ Undernet


Death is only the *Beginning*...
Back to top
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sat Sep 15, 2007 6:36 pm    Post subject: Reply with quote

Untested, but I guess this should do the trick, based on your examples:
Code:
regsub -all {([[:digit:].]+) 3 ([[:alpha:]]+)} $text {\1 Three Runs \2} out

_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
awyeah
Revered One


Joined: 26 Apr 2004
Posts: 1580
Location: Switzerland

PostPosted: Sun Sep 16, 2007 1:47 am    Post subject: Reply with quote

Well my idea was first to check with regexp to match the string and then proceed to substitute, you can substitute in many ways: regsub IS NOT the ONLY SOLUTION.

You can use nml's expression for regsub or use this then, lol:

Code:

set text [lindex [split $text] 0] Three Runs [lrange [split $text] 2 end]


This should also do the work for you, matches the two output strings you showed.
_________________
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
iamdeath
Master


Joined: 11 Feb 2005
Posts: 323
Location: *HeLL*

PostPosted: Sun Sep 16, 2007 7:07 am    Post subject: Reply with quote

Thanks alot nml, that solved the issue. awyeah I could use your expression but I don't know how to place it I was afraid I might disturb the whole code when regsub is easy and safe to use or remove Razz

Thanks once again awyeah and nml.

iamdeath
_________________
|AmDeAtH @ Undernet


Death is only the *Beginning*...
Back to top
View user's profile Send private message Visit poster's website
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