Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Need help on regexp

by 2teez (Priest)
on Aug 03, 2013 at 20:28 UTC ( #1047738=note: print w/ replies, xml ) Need Help??


in reply to Need help on regexp

Hi siva.snimmaka,
If your intention is to pick out "abcd_efgh-1.2.3" from "abcd_efgh-1.2.3-hjik-3.4.5.tar.gz", you can used

$_ = 'abcd_efgh-1.2.3-hjik-3.4.5.tar.gz'; print $1 if /(.+?)-[a-z].+?/i; ## prints abcd_efgh-1.2.3
or any of the previous solutions.
However, if your intention is to "match" only "abcd_efgh-1.2.3" in data that has several lines of similar strings, then I will go with kcot's solution.
Please also check up perlrequick and perlre if you have not.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me


Comment on Re: Need help on regexp
Download Code
Re^2: Need help on regexp
by kcott (Abbot) on Aug 04, 2013 at 06:19 UTC
    "... then I will go with kcot[t]'s solution."

    OK, that got a bit of a chuckle as /3$/ was really intended as a non-solution to highlight the lack of information provided in the question. :-)

    Actually, while the strings appear highly contrived, abcd_efgh-1.2.3 looks rather like the directory I might get when unpacking a tarball of v1.2.3 of the "abcd_efgh" application. If that's the case, then using the -d file test operator might be more appropriate than trying to craft a regex; but, until more information is forthcoming, who knows.

    -- Ken

      Hi kcott,
      OK, that got a bit of a chuckle as /3$/ was really intended as a non-solution to highlight the lack of information provided in the question...

      Sorry, I misunderstood your write up. But I kind of see a solution in it, that was why I mentioned it.
      Thinking if what the OP has is a file that contain say

      abcd_efgh-1.2.3 abcd_efgh-1.2.3-hjik-3.4.5.tar.gz
      then simply doing this:
      while (<DATA>){ print $_ if /3$/; }
      prints abcd_efgh-1.2.3, and thanks to if /3$/; of course using ONLY these OP strings. It could be a different thing if there are other strings ending with "3".
      All that been said on the assumption that, that was what was intended by the OP.

      If you tell me, I'll forget.
      If you show me, I'll remember.
      if you involve me, I'll understand.
      --- Author unknown to me

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1047738]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (15)
As of 2014-04-24 11:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (565 votes), past polls