in reply to Re: getting a regex to return an array of matches?
in thread getting a regex to return an array of matches?
and the file:#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use diagnostics; undef $/; my $file = "test.txt"; open INFILE, "<$file" or die "cant open file: $!\n"; my @arr = <INFILE>; close INFILE; foreach my $filepieces (@arr) { my @matches = $1 if ($filepieces =~ /alpha\|(.*?)\|/smg); if(@matches) { foreach my $match (@matches) { print "match: $match\n"; } } }
that's just an example, splitting on the pipe isn't an option, b/c my real files to parse don't look like thatalpha|beta|alpha|theta|alpha|gamma|alpha|episilon
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: getting a regex to return an array of matches?
by tirwhan (Abbot) on Feb 14, 2006 at 18:25 UTC | |
|
Re^3: getting a regex to return an array of matches?
by ikegami (Patriarch) on Feb 14, 2006 at 18:20 UTC | |
by rmexico (Novice) on Feb 14, 2006 at 18:52 UTC | |
by ikegami (Patriarch) on Feb 14, 2006 at 19:03 UTC | |
by PodMaster (Abbot) on Feb 15, 2006 at 05:13 UTC |