Hello,

I assume, you want single matched lines and not blocks of matched lines. Then you could use something like this:

use strict; use warnings; while (defined(my $line = <DATA>)) { if ($line =~ m{ \A N \d+ G \d+ X \d+ \.? \d* Y \d+ \.? \d* K \d+ \.? \d* J \d+ + \.? \d* H 1 M 25 \n \z | \A N \d+ M 20 \n \z | \A N \d+ G 45 \n \z | \A N \d+ G 01X \d+ \.? \d* Y \d+ \.? \d* C \d+ \.? \d* M 25 \ +n \z }xms) { print $line; } } __DATA__ N335G03X247.16Y580.07K6.89J96.62H1M25 N340M20 N345G45 N350G01X832.56Y692.92C275.44M25 N355M20 N360G46C0 N365G03Y720.88I146.74J13.98H36M25
which yields
N335G03X247.16Y580.07K6.89J96.62H1M25 N340M20 N345G45 N350G01X832.56Y692.92C275.44M25 N355M20
Update: added end-of-line anchors in regular expressions.

In reply to Re: Using regular expressions to find patterns in machine tool data by hexcoder
in thread Using regular expressions to find patterns in machine tool data by merrymonk

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.