Hi

I Have the following regex which I use when extracting information from different logfiles:

(?i-xsm:(?<mon>\w+)\s+(?<day>\d+)\s+(?<hour>\d+):(?<min>\d+):(?<sec>\d ++)\s*(?<host>\S+)\s*(?<prog>\S+)\/(?<proc>\S+)\[(?<pid>\d+)\]:\s*(?<i +d>\S+):\s*to=<(?<to>\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b)>,\s*r +elay=(?<name>\S+)\[(?<ip>\d+.\d+.\d+.\d+)\]:(?<port>[0-9]+),\s*delay= +(?<time>\d+\.\d+),\s*delays=(?<beforequeue>[0-9.]+)\/(?<inqueue>[0-9. +]+)\/(?<connect>[0-9.]+)\/(?<transmission>[0-9.]+),\s*dsn=(?<status>[ +0-9.]+),\s*status=sent\s*\((?<code>[0-9.]+)(?<message>.*)\))

I would like to extract all the named parameters like ?<mon>,?<day>,.... to make sure that I haven't used same name twice. The string is composed from substring I have in a database. I have tried different approaches but until now without success. I thought I could use some repetitive pattern like

(\?<(a-z+)>+

But I can't make it work. I could use the perl split function and probably get a list og the names.

any ideas ?

best regards

Peter Sørensen/Univ.Of.Southern.Denmark


In reply to How do I extract named variable names from regex string by maspsr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.