preg_match_all匹配锚链接中的字符串,不包括“<”和“>”字符

问题描述:

I need preg_match_all to match something like following:

<a href="cart.php?Stock=11.482&qty=1">Buy</a>

The code I'm using:

preg_match_all("'Stock=[^><]&qty=1\">Buy</a>'si", $source, $matches);

I need it to match everything before the &qty=1">Buy</a> and after the <a href="cart.php?Stock=, except the < or > characters. However, the following code does not work. Any suggestions?

我需要preg_match_all来匹配如下内容: p>

 &lt  ; a href =“cart.php?Stock = 11.482&amp; qty = 1”&gt;购买&lt; / a&gt; 
  code>  pre> 
 
 

我正在使用的代码:

  preg_match_all(“'Stock = [^&gt;&lt;]&amp; qty = 1 \”&gt;购买&lt; / a&gt;'si“,$ source,$ matches)  ; 
  code>  pre> 
 
 

我需要它来匹配&amp; qty = 1“&gt; Buy&lt; / a&gt; code>之后的所有内容以及&lt; a href =“cart.php?Stock = code>,,但&lt; code>或&gt; code>字符 em>除外。 ,以下代码不起作用。有任何建议吗? p> div>

Building further on your regex you just had to add a * after the character class

Stock=[^><]*&qty=1\">Buy</a>

If you want to match the number 11.482 add parenthesis so that group 1 contains this number

Stock=([^><]*)&qty=1\">Buy</a>