perl: How do I check if a line has only numeric characters

Posted on 2011-04-27
Last Modified: 2012-05-11
I want to check if a line has only numeric characters.  For example, in the log given below line 1 has only numerals but line two has numerals and alpha.  How can I check this?

20110425041723134	 Java Exception - NullPointerException

Open in new window

Question by:ambuli
    LVL 11

    Accepted Solution

    if ($string =~ /^\d+$/) { 
     print "$string contains only digits."; 

    Open in new window

    LVL 26

    Assisted Solution

    if ($line =~ /^\d+$/) {
       # yes, it is numerals only

    Author Comment

    Thank you both of you!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
    In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now