i.e. where are my expectations wrong?
You seem to assume that, for an alternation $a|$b, the regex engine does the following:
- It searches for alternative $a in the string</lii>
- If it doesn't find a match, it tries alternative $b
However, that's not the case. It does this:
- anchor pattern at start of string
- try to match alternative $a
- if it fails, try to match alternative $b
- if there's still no match, anchor pattern at the second character in the string, and start again from No. 2
Perhaps you want something along this line:
m/(?s:.*)Remediation Report\n\n(.+?)\n|^(.+?)\n/;
That searches for the Remediation Report\n\n(.+?)\n part of the regex anywhere in your string, and only if that fails it tries the second regex.
The record in question is one large string with newlines inside it
In the example script I posted, yes.
I updated the example data above to explain how each record is broken up better. I think the Data::Dumper output was a bit confusing. There is only one vulnerability name in each record, so /g shouldn't apply (I believe).
In scalar context the /g modifier doesn't mean "match as often as you can", but rather "start your match at pos $str, and set pos $str after the match". That means you can say stuff like this:
while ($str =~ m/($regex)/){
print $1, "\n";
}
But it's not the only application. You can use it to preserve the pos $str value, and then apply a different regex against it.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.