
KevinR
Veteran

Jul 29, 2009, 10:19 AM
Views: 3503
|
|
Re: [masaniparesh] Need help in tab separator string
|
|
|
Maybe this will do what you need:"
@array = ("test with one tab no space\ttest","test with one tab and space \ttest", "test with two tabs\t\ttest"); for (@array) { if (/^([^\t]+)(?<! )\t([^\t]+)$/) { print "$1 $2\n"; } else { print "Did not match\n"; } } ?<! is a zero-width negative look behind assertion. Zero-width assertions don't capture and store patterns in memory so $2 is not affected, in other words you don't have to use $3 to capture and store what is inside the third set of parentheses. Some reading: http://perldoc.perl.org/perlretut.html#Looking-ahead-and-looking-behind -------------------------------------------------
(This post was edited by KevinR on Jul 29, 2009, 10:20 AM)
|