-1

I want to find a pattern " and b_start in (ANYTHING)" and replace it with an empty string. The following code of mine does not work; i'm afraid it's due to the brackets in the pattern. Can anyone help to point out what's wrong with it? Many thanks.

$a=" and b_start in (2,3,5,6...) and b_end in (4,5,3,4,5...)";
$b=preg_replace("/ and b_start in \(.*\)/", "", $a);

I expect $b to return " and b_end in (4,5,3,4,5...)";

user1136314
  • 39
  • 1
  • 5

1 Answers1

0

You need to make you regex lazy, by default it is greedy in nature so it will match as much as possible Regex Ref

/ and b_start in \(.*?\)/

$a=" and b_start in (2,3,5,6...) and b_end in (4,5,3,4,5...)";
$b=preg_replace("/ and b_start in (.*?)/", "", $a);

echo $b;
Code Maniac
  • 37,143
  • 5
  • 39
  • 60