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 8524461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:41:35+00:00 2026-06-11T07:41:35+00:00

I am learning Perl regex, and I am trying to extract digits from a

  • 0

I am learning Perl regex, and I am trying to extract digits from a string, e.g.

my $text = "abc000142gh";

i.e. I would like to extract 000142 as a string in a scalar variable.

I have tried:

my $digits = $text ~= /(+d)/;
my $digits = $text ~= m/(+d)/;
my $digits = $text ~= m/(+d)/g;
my $digits = $text ~= /(+d)/g;

but none of them seem to work. Is there a way to do this with a one-liner?

  • 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-11T07:41:36+00:00Added an answer on June 11, 2026 at 7:41 am

    This works:

    my $text = 'abc000142gh';
    my ($digits) = $text =~ /(\d+)/;
    

    The differences:

    1. quotes around the string (not needed, but prefered).
    2. $digits in brackets to enforce list context. See perlop for details.
    3. The binding operator is =~, not ~=.
    4. \d means a digit, d stands for itself.
    5. + (repetition) is used after the symbol to repeat, not before.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not very good with Regex but I am learning. I would like
I have started learning perl and like to try out new things. I have
I'm still learning Perl at the moment and have been trying to get a
I'm learning Perl and building an application that gets a random line from a
I know from Learning Perl, 6th Ed. (ISBN: 978-1-449-30358-7) p.58 that ($x, $y) =
Forgive a novice question as I am learning Perl. I have some code like
I'm trying to work through a small Perl learning project that requires reading 4
Learning perl I just recently discovered the wonders of Moose! I'm trying to wrap
I'm still learning PERL so any help you could offer would be greatly appreciated.
I've just started learning perl and I am am confused by this exercise (from

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.