Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to return capture using Perl's grep and regex

Tags:

regex

grep

perl

Is it possible to return just the captured portion of a regex using Perl's grep function? I have code such as the following:

use LWP::Simple;
my $examples_content = get('http://example.com/javascript/reports/examples/');
my @hrefs = grep(/href="(.*)"/, split("\n", $examples_content));
print $hrefs[0];

What gets printed though is:

  • Stand-alone single-question charts
  • When I'd like just: simple_chart.html

    like image 258
    Dexygen Avatar asked Nov 25 '25 12:11

    Dexygen


    1 Answers

    Why are you using grep? This might do what you want:

    my @hrefs = $examples_content =~ /href="(.*?)"/g
    
    like image 57
    Amadan Avatar answered Nov 28 '25 15:11

    Amadan