Hi, Could anyone please help me here. I have been facing problems in getting two string separated by one and only one tab. The below code also works fine if there are more than one tab separator. I want to take all words before tab character in first string and all words after tab folder in second string. At the same time there must be only one tab separator. Moreover, if there is no tab in string then eveything should go in first string.

Hello, I have genuine reason for that and I know Perl pretty well but its complicated case for me. I just didn't want to give my complication scenario here.

I have been reading some strings from the file that contains many different formats and out of them one of the format I have given in my main question. The issue is I can use split only after I recognize the pattern. So to recognize each unique pattern, I have to use REGEX.

Kevin, small question. Your code works fine but is it possible to put restriction on trailing spaces. Note the first string has spaces before /t but still it will get succeed. In this case it should say "did not match. I could remove trailing spaces inside the matching statement but just wondering if it is possible to restrict it using REGEX.

?<! 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.

Thanks Kevin. I have missed one statement from my main question. "Moreover, if there is no tab in string then eveything should go in first string." That means the regular expression should also validate the string which doesn't have tab at all. I did it below way. It works fine but it doesn't meet one requirement "if there is a tab then there must be a non-empty string after that". I want "test with tab only /t" string to get unmatched but "test without tab" should be matched.Thanks.

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:

Code

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" );