| View previous topic :: View next topic |
| Author |
Message |
iamdeath Master

Joined: 11 Feb 2005 Posts: 323 Location: *HeLL*
|
Posted: Sat Sep 15, 2007 12:46 am Post subject: regexp issue |
|
|
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 |
|
 |
awyeah Revered One

Joined: 26 Apr 2004 Posts: 1580 Location: Switzerland
|
Posted: Sat Sep 15, 2007 9:07 am Post subject: Re: regexp issue |
|
|
| 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 |
|
 |
iamdeath Master

Joined: 11 Feb 2005 Posts: 323 Location: *HeLL*
|
Posted: Sat Sep 15, 2007 10:57 am Post subject: |
|
|
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 |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sat Sep 15, 2007 6:36 pm Post subject: |
|
|
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 |
|
 |
awyeah Revered One

Joined: 26 Apr 2004 Posts: 1580 Location: Switzerland
|
Posted: Sun Sep 16, 2007 1:47 am Post subject: |
|
|
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 |
|
 |
iamdeath Master

Joined: 11 Feb 2005 Posts: 323 Location: *HeLL*
|
Posted: Sun Sep 16, 2007 7:07 am Post subject: |
|
|
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
Thanks once again awyeah and nml.
iamdeath _________________ |AmDeAtH @ Undernet
Death is only the *Beginning*... |
|
| Back to top |
|
 |
|