0

Here's my test code:

$strings=array(
'Low Minimum',
'Low 10 Piece Minimum',
'10 piece minimum',
'20 piece minimum',
'low 6 piece minimum',
'100 piece minimum',
'This item is offered with a 1000 piece minimum',
'Place your order now. This item has a 75 piece minimum',
'Place your order now. This item has a low 75 piece minimum',
);

foreach($strings as $string)
  {
     echo preg_replace('/(low)? ?(\b[0-9]{0,3}\b) (piece minimum)/i',' Low Minumum',$string);
     echo '<br>';
  }

Here's the output:

Low Minimum
Low Minumum
Low Minumum
Low Minumum
Low Minumum
Low Minumum
This item is offered with a 1000 Low Minumum
Place your order now. This item has a Low Minumum
Place your order now. This item has a Low Minumum

Here is my desired output:

Low Minimum
Low Minumum
Low Minumum
Low Minumum
Low Minumum
Low Minumum
This item is offered with a 1000 piece minimum
Place your order now. This item has a Low Minumum
Place your order now. This item has a Low Minumum

The one that messes me up is the 4 digit number. So, "piece minimum" should only match if some part of what's before it also matched. How do I write this?

4

1 回答 1

1

对于您想要的输出,您需要更改一个小错误。

代替..

[0-9]{0,3}

它应该是..

[0-9]{1,3}
于 2013-10-02T18:25:25.003 回答