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

Re: using regular expression to extract subset from a line

by DamnDirtyApe (Curate)
on Dec 30, 2004 at 19:54 UTC ( #418369=note: print w/replies, xml ) Need Help??


in reply to using regular expression to extract subset from a line

I'll leave the analysis of what you've got to someone who's better at regexps than I, but if you're simply looking to extract the argument from a space-delimited string that ends in "makefile", try something simpler like this:

#! /usr/bin/perl -w use strict; my $old_str = 'make -r -f ..\../tools/cell/makefile cell.lib'; my $new_str = ( $old_str =~ /\s+(\S*makefile)/ )[0]; print "New string: $new_str$/"; __END__

HTH

Update: You could do this with split and grep also:

my $new_str = ( grep { /makefile$/ } split /\s+/, $old_str )[0];

_______________
DamnDirtyApe
Those who know that they are profound strive for clarity. Those who
would like to seem profound to the crowd strive for obscurity.
            --Friedrich Nietzsche

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2020-06-07 07:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (42 votes). Check out past polls.

    Notices?