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

  • Home
  • SEARCH
  • 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 6618645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:51:41+00:00 2026-05-25T20:51:41+00:00

I think I’m missing something simple here… $key = deco-1-LB-700F:MAR:40; if ($key =~ m/deco-(.*?)-(.*?)-(.*?):(.*?):(.*?)/)

  • 0

I think I’m missing something simple here…

$key = "deco-1-LB-700F:MAR:40";
  if ($key =~ m/deco-(.*?)-(.*?)-(.*?):(.*?):(.*?)/) {
      print "1=$1 2=$2 3=$3 4=$4 5=$5";
  }

This results in the output: 1=1 2=LB 3=700F 4=MAR 5=

Why isn’t $5 returning the value 40 ?

Cheers, Stu

  • 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-05-25T20:51:42+00:00Added an answer on May 25, 2026 at 8:51 pm

    Because .*? is lazy and will match zero characters if it can. Anchor the regex to the end of the string:

    $key =~ m/deco-(.*?)-(.*?)-(.*?):(.*?):(.*?)$/
    

    But it’s nearly always better to use something more explicit than the catch-all .* and .*?. Tell the regex engine exactly what you want to allow to match. Assuming that the delimiters - and : never occur in the actual matches, I suggest

    $key =~ m/deco-([^-]*)-([^-]*)-([^:]*):([^:]*):([^:]*)$/
    
    • [^-] means “match any character except -“.
    • [^:] means “match any character except :“.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I'm missing something basic here. Why is the third IF condition true?
I think I'm missing something basic here. Any explanation or pointers to previously asked
Think Windows Explorer's 'Details' view. I need to output my database to this view.
I think this is a relatively simple problem. I wish to obtain some functionality
Think this is my target key in registry: [HKEY_CURRENT_USER\System\Majid\0] GUID=hex:60,de,2a,56,51,b2,e0,11,80,01,44,45,53,54,00,00 as you can see
I think that I am misunderstanding something about how jquery $(this) works. In my
I think I got all the steps down but I must be missing something
I think this may sound very straight forward, but still something is not working
Think: tiling my emacs window with eshells, a la xmonad. Is this possible? I
I think most people know how to do this via the GUI (right click

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.