in reply to Re^4: Regex problems using '|'
in thread Regex problems using '|'
That's the behavior I want with regards to the rest of the records.
After looking at the updated data I think that you need two regexes for that:
use strict; use warnings; my $str = do { local $/; <DATA> }; if ($str =~ m/Remediation Report\n\n(.+?)\n/g){ print $1, $/; while ($str =~ m/\n\n(.*)\n/g){ print $1, $/; } } __DATA__ thread-index: AcjoCau17Ri90HMJR8qoukn2A1g7ng== MIME-Version: 1.0 # rest of data goes here
The output is:
Adobe Flash Player Multiple Vulnerabilities - April 2008 - IE Adobe Flash Player Multiple Vulnerabilities - April 2008 - Mozilla/Ope +ra Adobe Reader/Acrobat 8.1.2 and 7.1.0 Update - Acrobat 7.x
The trick is to use the /g-modifier on the first regex although it matches only once. That way pos $str will not be reset, and the next regex match starts where the previous left off.
Also note that ^ will anchor to the start of the string (not to the start of a line) unless the /m modifier is present.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Regex problems using '|'
by romandas (Pilgrim) on Jul 22, 2008 at 12:09 UTC | |
by JavaFan (Canon) on Jul 22, 2008 at 12:45 UTC | |
by romandas (Pilgrim) on Jul 22, 2008 at 13:05 UTC | |
by moritz (Cardinal) on Jul 22, 2008 at 13:06 UTC | |
by romandas (Pilgrim) on Jul 22, 2008 at 13:17 UTC |