Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8496045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:44:33+00:00 2026-06-10T23:44:33+00:00

I have a quick question. What am I doing wrong in below code: #!/usr/bin/perl

  • 0

I have a quick question. What am I doing wrong in below code:

#!/usr/bin/perl -w
use strict;
my $num = "12345";
print "$num \n" if $num =~ m/\d{1,3}/;

As my number is 5 digits long, I was hoping that the output should not print anything because if statement is looking for a number with at least 1 digit and maximum 3 digits. But my script pints the output as below:

# perl num.pl 
12345 

Am I misunderstanding the above regex?

Thanks.

EDIT:

So ,Actually I am trying to match an IP address like string. e.g. i want to match 11.222.3.444 but it did not work with m/\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}/
so i started working on a single string containing only the number and hence then posted this on the stack overflow.

If i have to put ^ OR $ then how should i go about using them if I want to match IP address like string s mentioned above.

Thanks for you time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T23:44:35+00:00Added an answer on June 10, 2026 at 11:44 pm

    What your perl code says is, “inside the string $num can you find a string at least 1 character at most 3 characters made only of numbers.” The answer of course is yes.

    What you want is

    print "$num \n" if $num =~ m/^\d{1,3}$/;

    Which means “inside the string $num starting at the first character and going to the last character is there a string at least 1 character long at most 3 characters long made only of numbers.”

    If you are trying to find something like an ip address
    regexp to match IP address is a good discussion of how to do that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a quick question: Somebody have a code snippet to hide a window
I have this quick question regarding cost estimation using Function Points. We are doing
I have a quick question about jQuery selectors. Is doing this: $('.class_el_1, .class_el_2').hide(); The
Below is a quick example of what I am doing. Basically, I have multiple
I have a quick behavior question. When I call the following lines of code:
I have quick question about text parsing, for example: INPUT=a b c d e
I have quick question for you SQL gurus. I have existing tables without primary
I have a quick question about something I imagine must be pretty easy -
I have a quick question that I can't seem to find online. I am
I have this quick question, i have got the username variable from a form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.