In PHP how do I complete a regex that returns only what was grouped -


I want to make a regex using grouping. I only take interest in the group, I want to return all this, is it possible?

$ haystack = '& lt; A href = "/ foo.php" & gt; Go to Foo & lt; / A & gt; '; $ Needle = '/href="(.*)">/'; Preg_match ($ needle, $ stack of stacks match $); Print_r (matches $); // output // array ([0] = & gt; href = "/ foo.php" & gt; [1] = & gt; /foo.php) // I want: // array ([0] = >>

Actually it is possible with exploration. Instead of:

  href = "(. *)" & Gt;  

You want

  (? & Lt; = href = "). * (? =" & Gt;)  
> now it (and so captured in group 0) any . * which will be preceded by href = " followed by " & gt; . Note that I highly doubt that you actually have . *? is required, meaning reluctant rather than greedy.

  --- A - Z --- A-- Z ---- ^^^^^^^^^^^ A * Z  
< P> In any case, it looks like PHP's preg PCA, so it should support settings.

regular- expressions.info link

    • execute PHP's preg PCRE flavor Please.
    • PCRE:
      • (? = Regex) (positive lookhead): Yes
      • > & lt ;? Php $ haystack = '& lt; A href = "/ foo.php" & gt; Go to Foo & lt; / A & gt; & Lt; A href = "/ bar.php" & gt; Bar to take & lt; / A & gt; '; $ Needle = '/ (? & Lt; = href = "). *? (? =" & Gt;) /'; Preg_match_all ($ needle, $ stack of stacks coincides with $); Print_r (matches $); ? & Gt;

        generates:

          array ([0] => array ([0] => /foo.php [1] = & Gt; / Bar.php))  

        Related Questions

        These are mostly Java, but the part of the resux is included using pendant / convulsions:


Comments