
KevinR
Veteran

Jan 31, 2007, 4:10 PM
Post #10 of 12
(21664 views)
|
Re: [seahorse] Help with an if regx statement
[In reply to]
|
Can't Post
|
|
another approach:
$s1 = "[0],[0,1],[1,0,3,5]"; $s2 = "[[0],[0,2]]"; $s3 = "[[0]stuff,morestuff[0,4]]"; $s4 = ",[0][0,1,2][0,1]"; $s5 = "[0]stuff[0,1][1,0,2,5]]stuff,morestuff]"; $s6 = "[0]stuff[0,1][1,0,2,5][stuff,morestuff["; $s7 = "[0][0,1,2][0,1]"; $s8 = "[0]stuff[0,1][1,0,2,5]"; my $n = 1; for ($s1,$s2,$s3,$s4,$s5,$s6,$s7,$s8) { my $r = $_; s/\[[^\]]*\]//g; my $p = (/,/)? BAD: GOOD; print "string \$s$n) $p: $r\n"; $n++; } output:string $s1) BAD: [0],[0,1],[1,0,3,5] string $s2) BAD: [[0],[0,2]] string $s3) BAD: [[0]stuff,morestuff[0,4]] string $s4) BAD: ,[0][0,1,2][0,1] string $s5) BAD: [0]stuff[0,1][1,0,2,5]]stuff,morestuff] string $s6) BAD: [0]stuff[0,1][1,0,2,5][stuff,morestuff[ string $s7) GOOD: [0][0,1,2][0,1] string $s8) GOOD: [0]stuff[0,1][1,0,2,5]
but if the occurances and frequencies of [] can be anywhere in the string in any combination this might prove to be less than 100% accurate. Pauls suggestion above might work better in that case. -------------------------------------------------
|