oysterperl has asked for the wisdom of the Perl Monks concerning the following question:
I want to get all test* in a variable. I am trying the code below:Grab this 'test1' (repeat/new) many lines ... .. .. Grab this 'test2' (repeat/new) many lines ... .. .. Grab this 'test3' (repeat/new)
With this, grab_array shows the entire line in it like: 'test3' (repeat/new) I don't want the (repeat/new) but only the test* in grab_array. I have tried the following: $current_line =~ /Grab this\s+(.+)/ $current_line =~ /Grab this\s+(.)/ but it did not work. Appreciate any help with this. Thanks.while ($current_line = <$file_pointer>) { if ($current_line =~ /Grab this\s+(.*)/) { $GRAB = $1; push (@grab_array, $GRAB); print "$GRAB"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to get only the next word matching the regex in the line
by GrandFather (Saint) on Nov 11, 2019 at 02:39 UTC | |
by AnomalousMonk (Archbishop) on Nov 11, 2019 at 04:11 UTC | |
by oysterperl (Novice) on Nov 11, 2019 at 05:29 UTC | |
|
Re: How to get only the next word matching the regex in the line
by LanX (Saint) on Nov 11, 2019 at 02:28 UTC | |
by oysterperl (Novice) on Nov 11, 2019 at 05:30 UTC | |
by LanX (Saint) on Nov 11, 2019 at 09:48 UTC | |
|
Re: How to get only the next word matching the regex in the line
by swl (Prior) on Nov 11, 2019 at 02:27 UTC |