What I would suggest is:     print "$1\n" if (/^(.*?)\s*\d+$/); This will have the effect of removing the trailing space from the line.

I'm not sure if this will be an issue for your application or not, but your program might get a bit carried away if you (or someone else) spaced out some of your expressions, such as:
x = ReallyLongFunctionNameNumber1() + 130 + AnotherCrazyLongFunctionNameThatIsOnItsOwnLine();
I would presume that you don't want the program to pick up on that line, in which case, a slightly safer version might be to put a semi-colon in your regexp, like so:     print "$1\n" if (/^(.*?;)\s*\d+$/); Or to demand a specific quantity of numbers, such as 5:     print "$1\n" if (/^(.*?)\s*\d{5}$/); Although, to be truly "safe", you would want to change the format of your numerical markup system slightly, such as turning it into a comment, like:     int i; // #20005 Where '// #20005' is not very likely to show up anywhere else in your code.

Though, of course, this will depend on the context of your application, and it might be way over-kill.

In reply to Re: Regular Expression (Fix) by tadman
in thread Matching lines in a file that end in numbers (was: regular expression) by ashok

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.