CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions: Re: [masaniparesh] Need help in tab separator string: Edit Log



KevinR
Veteran


Jul 29, 2009, 10:19 AM


Views: 7843
Re: [masaniparesh] Need help in tab separator string

Maybe this will do what you need:"


Code
@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)


Edit Log:
Post edited by KevinR (Veteran) on Jul 29, 2009, 10:20 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives