Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Because the <code>+</code> tells it to repeat the exact stuff inside brackets <code>(?:"(.+?)",?)</code> one or more times. So it will match the <code>"eee"</code> string, end then look for repetitions of that <code>"eee"</code> string, which it does not find. </p> <pre><code>use YAPE::Regex::Explain; print YAPE::Regex::Explain-&gt;new(qr/var strings = \[(?:"(.+?)",?)+/)-&gt;explain(); The regular expression: (?-imsx:var strings = \[(?:"(.+?)",?)+) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- var strings = 'var strings = ' ---------------------------------------------------------------------- \[ '[' ---------------------------------------------------------------------- (?: group, but do not capture (1 or more times (matching the most amount possible)): ---------------------------------------------------------------------- " '"' ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- .+? any character except \n (1 or more times (matching the least amount possible)) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- " '"' ---------------------------------------------------------------------- ,? ',' (optional (matching the most amount possible)) ---------------------------------------------------------------------- )+ end of grouping ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- </code></pre> <p>A simpler example would be:</p> <pre><code>my @m = ('abcd' =~ m/(\w)+/g); print "@m"; </code></pre> <p>Prints only <code>d</code>. This is due to:</p> <pre><code>use YAPE::Regex::Explain; print YAPE::Regex::Explain-&gt;new(qr/(\w)+/)-&gt;explain(); The regular expression: (?-imsx:(\w)+) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- ( group and capture to \1 (1 or more times (matching the most amount possible)): ---------------------------------------------------------------------- \w word characters (a-z, A-Z, 0-9, _) ---------------------------------------------------------------------- )+ end of \1 (NOTE: because you are using a quantifier on this capture, only the LAST repetition of the captured pattern will be stored in \1) ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- </code></pre> <p>If you use the quantifier on the capture group, only the last instance will be used.</p> <hr> <p>Here's a way that works:</p> <pre><code>my $str = &lt;&lt;STR; ... ... var strings = ["aaa","bbb","ccc","ddd","eee"]; ... ... STR my @matches; $str =~ m/var strings = \[(.+?)\]/; # get the array first my $jsarray = $1; @matches = $array =~ m/"(.+?)"/g; # and get the strings from that print "@matches"; </code></pre> <hr> <p><strong>Update</strong>: A single-line solution (though not a single regex) would be:</p> <pre><code>@matches = ($str =~ m/var strings = \[(.+?)\]/)[0] =~ m/"(.+?)"/g; </code></pre> <p>But this is highly unreadable imho.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload