Hello folks,
I have a little problem like that:
In a file are different sections. In these sections are key-value pairs. Every pair can occur arbitrary times. To be more sophisticated, every section can have several names. Sections are divided by one or more empty lines. An example:
{section1}
key1: value1_1
key2: value2_1
key2: value2_2
key3: value3_1
...
{section2}{section3}
key1: value1_1
key2: value2_1
key2: value2_2
key2: value2_3
key3: value3_1
...
My problem is to find out all lines of a certain key in a distinct section, e.g. find all values of key2 in section 2. I tried with and without look-aheads and look-behinds, all I get is either the first or the last value, but never all of them (should be 3 elements):
my @data = $text =~ /(?<=\{section2\})(?:[^\[\]]+\n)*(?:key2:\s+([^\n] ++?)\s*?\n)/sg; my @data = $text =~ /(?:\{section2\}(?:\{section[\d]+\})*\n)(?:\w+?:\s +*(?:.+?)\s*?\n)*?(?:key2:\s+([^\n]+?)\s*?\n)/sg;
UPDATE: I try to tune Net::XWhois (DENIC parser), which uses an engine like
@matches = $self->{ Response } =~ /${$self->{Parser}}{$key}/sg;
to get the entries, so my task is to set up a new parser.
Is it possible at all to solve this problem?
Thanks for any hint
Marco
In reply to Stuck with RegEx (Parsing whois output) by marsch
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |