0

I want to remove the excess comma in my output string inside a parenthesis.

 $data= "item_id IN ( '1','2',) AND nt_id IN ( 'er1','er2',) AND";

I removed the Excess 'AND' by using rtrim funtion.

$trimValues = rtrim($data,'AND') ;

But how can I remove the comma inside a parenthesis?

1 Answer 1

1
,(?=\s*\))

You can use this and replace by empty string.See demo.

https://regex101.com/r/rkDV4X/1

$re = '/,(?=\s*\))/';
$str = 'item_id IN ( \'1\',\'2\',) AND nt_id IN ( \'er1\',\'er2\',) AND';
$subst = '';

$result = preg_replace($re, $subst, $str);

echo "The result of the substitution is ".$result;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.