0

I want to find a regex that selects a specific string that is defined by it's beginning & ending characters, through multilines, to be replaced by empty string. suppose that I have the following string for example:

I want to select every string that begins with -- and ends with ;

$str = 'some text --text_to_be_replaced; and another text -- text
to
be
replaced; and some text...;';

what I've tried:

$str = preg_replace('/--(.*);/s', '', $str);

but the returned result is: some text while the expected result is some text and another text and some text...;

Mohammad
  • 3,449
  • 6
  • 48
  • 75

1 Answers1

0

Your regex is too greedy, try this one:

/--([^;]*);/s

Demo

mrzasa
  • 22,895
  • 11
  • 56
  • 94