Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Actually this is possible with lookarounds. Instead of:</p> <pre><code>href="(.*)"&gt; </code></pre> <p>You want</p> <pre><code>(?&lt;=href=").*(?="&gt;) </code></pre> <p>Now this will match (and therefore capture into group 0) any <code>.*</code> that is preceded by <code>href="</code> and followed by <code>"&gt;</code>. Note that I highly suspect that you really need <code>.*?</code> instead, i.e. reluctant instead of greedy.</p> <pre><code>---A--Z---A--Z---- ^^^^^^^^^^^ A.*Z </code></pre> <p>In any case, it looks like PHP's <code>preg</code> is PCRE, so it should support lookarounds.</p> <h3>regular-expressions.info links</h3> <ul> <li><a href="http://www.regular-expressions.info/lookaround.html" rel="nofollow noreferrer">Lookaround</a></li> <li><a href="http://www.regular-expressions.info/refflavors.html" rel="nofollow noreferrer">Flavor comparison</a> <ul> <li>PHP's <code>preg</code> functions implement the PCRE flavor.</li> <li>PCRE: <ul> <li><code>(?=regex)</code> (positive lookahead): YES</li> <li><code>(?&lt;=text)</code> (positive lookbehind): fixed + alternation</li> </ul></li> </ul></li> </ul> <hr> <h3>Demonstration</h3> <pre><code>&lt;?php $haystack = '&lt;a href="/foo.php"&gt;Go To Foo&lt;/a&gt;&lt;a href="/bar.php"&gt;Go To Bar&lt;/a&gt;'; $needle = '/(?&lt;=href=").*?(?="&gt;)/'; preg_match_all($needle,$haystack,$matches); print_r($matches); ?&gt; </code></pre> <p><a href="http://ideone.com/P5jRM" rel="nofollow noreferrer">Running this on ideone.com</a> produces:</p> <pre><code>Array ( [0] =&gt; Array ( [0] =&gt; /foo.php [1] =&gt; /bar.php ) ) </code></pre> <h3>Related questions</h3> <p>These are mostly Java, but the regex part covers using lookarounds/assertions:</p> <ul> <li><a href="https://stackoverflow.com/questions/2819933/java-split-is-eating-my-characters/">Java split is eating my characters</a></li> <li><a href="https://stackoverflow.com/questions/2406633/can-you-use-zero-width-matching-regex-in-string-split">Can you use zero-width matching regex in String split?</a></li> <li><a href="https://stackoverflow.com/questions/2559759/how-do-i-convert-camelcase-into-human-readable-names-in-java">How do I convert CamelCase into human-readable names in Java?</a></li> </ul>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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