A request for real life regepx with alternations, well that's fun !

Here's one that i use to do some matching on HP-UX iostat output :

m/^ ( NANQ|INF|NANS| # Possible non numerics \d+ # a number ... (?:[,\.]\d+)? # ... with an optional decimal part ) # memorise the value of : tin . \s+ ( NANQ|INF|NANS| # The same one \d+ (?:[,\.]\d+)? ) # memorise the value of : tout . \s+ (?:[\d\s\.,]|NANQ|INF|NANS)+ # Rest of the line . $/x
The non numeric values were added afterwards, after they showed in some iostat output were i did not expected them. The regep thus allowed me to fix an annoying behaviour with minimal impact.

Another one :

s/^\d\d:\d\d:\d\d\s*(?:CPU|INTR)\s*//
This is some sar linux result line .

Now some vmstat with sunOS:

s/de\s+sr\s+(\w\d|\w\w|\w\w\d|--|\s)+in\s+sy/de sr in sy/g

Cheers,
zlr.


In reply to Re: Need regexes with alternations in them for testing perl... by ZlR
in thread Need regexes with alternations in them for testing perl... by demerphq

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.