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.

Need help with regexp :)

Old posts that have not been replied to for several years.
Locked
T
ThEdGE

Post by ThEdGE »

Got some problems with the damn regexp being a pain in the ass :smile:

Well hope someone can figure it out,
lets say we have a string:

"one two three four five six"

and i would like to have the word before "four" in var using regexp.

So that the new string will be "three",
the best i got was:

regexp {( ).*( four )} $string string

but this will return "two three" :sad:

Anyawy im clueless tried several combinations, but no luck. Hope anyone can help me out.
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

set str "one two three four"
regexp {([^ ]*) four} $str total_match three

Now $total_match will be "three four" and $three will be "three"

But why do you want a regexp?

set three [lindex [split $str] 2]
T
ThEdGE

Post by ThEdGE »

well the string i showed you was just a example.

The code is going to be used on strings that are not always the same but follow the same pattern within the string.

Anyhow thanks alot, works just fine :smile:

Appreciate it.



<font size=-1>[ This Message was edited by: ThEdGE on 2002-03-23 15:13 ]</font>
Locked