Terry,
Something like this should work. Note this is not tested. Here's a little explanation too. The '.' matches any character as you know and the '*' says any number of those any characters. The key is the '?' after the '*' which makes the match "non-greedy". Normally the '*' matches as many characters as it can and still satisfy the regular expression. Adding the '?' makes it match as few characters as it can and still satisfy the expression. #!/usr/bin/perl while (<DATA>) { push(@files, /(BEG.*?KEYWORD.*?END)/g ); } print $_ . "\n" foreach (@files); Matt ________________________________ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Vaughn, Terry Sent: Tuesday, February 06, 2007 9:42 AM To: perl-unix-users@listserv.activestate.com Subject: [Perl-unix-users] Regex question Can someone point out what I appear to be missing ? I am trying to extract BEG ... KEYWORD .. END from the DATA string below: I only want the BEG to END portion where KEYWORD is in between. As is..... I get the entire string. <script> #!/usr/bin/perl while (<DATA>) { push(@files, /(BEG.+KEYWORD(?:(?!BEG.+KEYWORD).)*END)/g ) ; } print $_ . "\n" foreach (@files); __DATA__ BEG blah blah blah more blah ENDBEG blah blah blah more blah KEYWORD END </script> Terry
_______________________________________________ Perl-Unix-Users mailing list Perl-Unix-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs