
KevinR
Veteran

Jul 29, 2009, 12:23 PM
Post #14 of 14
(16831 views)
|
Re: [masaniparesh] Need help in tab separator string
[In reply to]
|
Can't Post
|
|
What you want to do is not best served by trying to write one rather complex regexp, you should use two or maybe even three and use them in a hierarchical order of importance. Something like this is more practical:
my @array = ("test with one tab no space\ttest", "test with one tab and space \ttest", "test with two tabs\t\ttest", "test with no tab", "", "test with nothing after tab\t", "test with one tab no space\tand non empty string after tab" ); for (@array) { if (length($_) > 0 && !/\t/) { print "Matched first condition: [$_]\n"; } elsif (/^([^\t]+)(?<! )\t([^\t]+)$/) { print "Matched second condition: [[$1] [$2]]\n"; } else { print "Did not match at all: [$_]\n"; } } -------------------------------------------------
|