combine two pattern matches to one match? 
Author Message
 combine two pattern matches to one match?

Can someone combine the following two pattern matches to one match?

  perl -ne "next if /-- \s* INFILE/ix;
            if (/INFILE \s+ ' \s* (\S+) \s* '/ix) { print \$1; last; }"

That is, change above to:

perl -ne "if (/ you pattern match /) { print \$1; last; }"

Thanks.

PS: You can post, but an email copy to me is appreciated.



Sat, 24 Jul 2004 02:27:13 GMT  
 combine two pattern matches to one match?

Quote:

> Can someone combine the following two pattern matches to one match?

>   perl -ne "next if /-- \s* INFILE/ix;
>             if (/INFILE \s+ ' \s* (\S+) \s* '/ix) { print \$1; last; }"

> That is, change above to:

> perl -ne "if (/ you pattern match /) { print \$1; last; }"

perl -ne"print $1 and last if /(?<!--\s*INFILE)INFILE \s+ ' \s* (\S+)
\s* '/ix"

John
--
use Perl;
program
fulfillment



Sat, 24 Jul 2004 04:39:45 GMT  
 combine two pattern matches to one match?
On Feb 5, John W. Krahn said:

Quote:

>> Can someone combine the following two pattern matches to one match?

>>   perl -ne "next if /-- \s* INFILE/ix;
>>             if (/INFILE \s+ ' \s* (\S+) \s* '/ix) { print \$1; last; }"

>perl -ne"print $1 and last if /(?<!--\s*INFILE)INFILE \s+ ' \s* (\S+)
>\s* '/ix"

Nope.  That look-behind isn't constant width.  It SUCKS (IMHO) that Perl
can't do this.  I'm going to fix it some day.

--

RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.



Sat, 24 Jul 2004 05:27:50 GMT  
 combine two pattern matches to one match?

Quote:
>> Can someone combine the following two pattern matches to one match?

>>   perl -ne "next if /-- \s* INFILE/ix;
>>             if (/INFILE \s+ ' \s* (\S+) \s* '/ix) { print \$1; last; }"

>> That is, change above to:

>> perl -ne "if (/ you pattern match /) { print \$1; last; }"

>perl -ne"print $1 and last if /(?<!--\s*INFILE)INFILE \s+ ' \s* (\S+)
>\s* '/ix"

Is Variable length lookbehind implemented in your Perl?
Not here in v5.6.1. Thanks.


Sat, 24 Jul 2004 09:23:40 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. indexing versus pattern matching, or combining the two

2. Pattern matching spanning more than one line and substitution between two files -

3. Matching two patterns at once

4. pattern matching across two lines

5. pattern matching across two lines

6. Matching two patterns in a DB. (general expressions...)

7. Pattern bug matching whitespace in multi-line match?

8. Pattern Match - substitute a string after the match

9. pattern matching; see content file as one string

10. Pattern matching, grabing everything right of the match

11. Pattern Match - Don't Understand this particular one

12. Help on pattern matching, very diffcult one

 

 
Powered by phpBB® Forum Software