I am replacing some code to del and ins html tag using PHP.
For example, my code is:
$text = 'This is (foo)((bar))';
$text = preg_replace('/\((.*)\)*/', '<del>$1</del>', $text);
$text = preg_replace('/\(\((.*)\)\)/', '<ins>$1</ins>', $text);
Output I get:
This is <del>foo)((bar)</del>
Which means, it catches the last closing bracket.
Output I want:
This is <del>foo</del><ins>bar</ins>
Thwn, how to catch the first closing bracket?
Yes, I can solve it by replacing ins tag first like this:
$text = 'This is (foo)((bar))';
$text = preg_replace('/\(\((.*)\)\)/', '<ins>$1</ins>', $text);
$text = preg_replace('/\((.*)\)*/', '<del>$1</del>', $text);
But is there any better solution without moving like this?