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.
Old posts that have not been replied to for several years.
ProXy
Op
Posts: 126 Joined: Sun Aug 11, 2002 3:09 pm
Post
by ProXy » Tue Mar 11, 2003 1:08 pm
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
Papillon
Owner
Posts: 724 Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no
Post
by Papillon » Tue Mar 11, 2003 2:08 pm
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
ProXy
Op
Posts: 126 Joined: Sun Aug 11, 2002 3:09 pm
Post
by ProXy » Tue Mar 11, 2003 10:15 pm
Well, the string is not static, so I have to check, that i split between the chars and the [ bracket...
stdragon
Owner
Posts: 959 Joined: Sun Sep 23, 2001 8:00 pm
Contact:
Post
by stdragon » Wed Mar 12, 2003 1:47 am
set test {HTP[1:2:3]}
foreach {part1 part2} [split $test {[}] {}
part1 = HTP
part2 = 1:2:3]
Papillon
Owner
Posts: 724 Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no
Post
by Papillon » Wed Mar 12, 2003 3:54 am
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