in reply to Get data from javascript

For your specific example (not tested):

/replace_image\(([^,]+)/
or
/replace_image\(["']([^"']+)/

should fetch the URL into $1 for you.

Replies are listed 'Best First'.
Re^2: Get data from javascript
by Anonymous Monk on Jul 11, 2016 at 15:02 UTC
    The url in the JS is fixed per page, so one per page. I parse lots of pages and want to extract the URL. I tried the code you gave
    my $wanted = $page =~ /push_delayed_image\(([^,]+)/; print Dumper $wanted;
    But this prints $VAR - 1; not the URL
      You need list context to get the capture groups back.

      my ($wanted) = $page =~ /push_delayed_image\(([^,]+)/; # ^ ^

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      Alternately to what Choroba said, you could:

      $page =~ /push_delayed_image\(([^,]+)/; my $wanted = $1;

      Often, I'm using a conditional, so will do this:

      if ($page =~ /push_delayed_image\(([^,]+)/) { my $wanted = $1; ... }