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.

regexp...

Old posts that have not been replied to for several years.
Locked
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

regexp...

Post by ProXy »

Hi, I have a string that contains a word like "HTP[1:2:3]". Is it possible to split the word to "HTP" and "[1:2:3]" with regexp? Or is it just possible to split the string with other commands? Would be nice for some support :)

Greetings,
ProXy
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

mmm I'm not to good with regexp... but something like this?

Code: Select all

set test "HTP[1:2:3]"
regexp {(HTP)(\[1:2:3\])} $test var1 var2 var3

var1 = HTP[1:2:3]
var2 = HTP
var3 = [1:2:3]
don't kill me if this is wrong ;)
Elen sila lúmenn' omentielvo
P
ProXy
Op
Posts: 126
Joined: Sun Aug 11, 2002 3:09 pm

Post by ProXy »

Well, the string is not static, so I have to check, that i split between the chars and the [ bracket...
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

set test {HTP[1:2:3]}
foreach {part1 part2} [split $test {[}] {}


part1 = HTP
part2 = 1:2:3]
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

since you asked about regexp... I tested a littlebit and came up with this cute line... hehe
it will just split if the var follows the "characters[num:num:num]" pattern

Code: Select all

set test "blsBLSBbsuaBYY[343:43:4]"
regexp {([a-z A-Z]*)(\[([0-9]+:)+[0-9]+\])} $test var1 var2 var3

var2 = blsBLSBbsuaBYY
var3 = [343:43:4]
Elen sila lúmenn' omentielvo
Locked