Matching two patterns at once 
Author Message
 Matching two patterns at once

I have a multi-line output text that contains pertinent information between
two different patterns. I'm trying to split the string to build an array
that would contain the text comprised between the two search patterns. To
illustrate: if I have the string "I don't know much about perl" and I want
to extract "much about" looking for anything comprised between "know" and
"perl", can I do that in one go or do I need two splits?

This doesn't work properly:

Thanks for any help,
Stephan.



Sun, 02 Oct 2005 22:01:48 GMT  
 Matching two patterns at once

Quote:

> I have a multi-line output text that contains pertinent information between
> two different patterns. I'm trying to split the string to build an array
> that would contain the text comprised between the two search patterns. To
> illustrate: if I have the string "I don't know much about perl" and I want
> to extract "much about" looking for anything comprised between "know" and
> "perl", can I do that in one go or do I need two splits?

> This doesn't work properly:




/ Gunnar

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



Sun, 02 Oct 2005 22:00:57 GMT  
 Matching two patterns at once

Quote:

> I have a multi-line output text that contains pertinent information between
> two different patterns. I'm trying to split the string to build an array
> that would contain the text comprised between the two search patterns. To
> illustrate: if I have the string "I don't know much about perl" and I want
> to extract "much about" looking for anything comprised between "know" and
> "perl", can I do that in one go or do I need two splits?

> This doesn't work properly:



($text) = ($output =~ /know(.*)perl/);
Quote:

> Thanks for any help,
> Stephan.



Sun, 02 Oct 2005 22:42:02 GMT  
 Matching two patterns at once

Quote:

> I have a multi-line output text that contains pertinent information
between
> two different patterns. I'm trying to split the string to build an array
> that would contain the text comprised between the two search patterns. To
> illustrate: if I have the string "I don't know much about perl" and I want
> to extract "much about" looking for anything comprised between "know" and
> "perl", can I do that in one go or do I need two splits?

> This doesn't work properly:



You might try a regex instead of split:

use strict;
use warnings;
use diagnostics;

my $text = "I don't know much about perl";

my ($match) = $text =~ /know (.+) perl/;

print $match;

hth,

Jodyman



Tue, 04 Oct 2005 05:26:35 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. combine two pattern matches to one match?

2. indexing versus pattern matching, or combining the two

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

4. pattern matching across two lines

5. pattern matching across two lines

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

7. Working with two streams at once: ack pth!

8. Doing two tasks at once

9. File I/O: want to compare two or more lines @ once

10. Regular Expressions/Pattern Matching/Unordered pattern

11. pattern as a sentence in pattern matching

12. Two scripts at once?

 

 
Powered by phpBB® Forum Software