I'm looking for a regex pattern which will filter a string.
If the last 2 characters are ,}
it should remove the ,
from the string.
Example:
helloworld,}
//^
should become
hellworld}
//^
I'm looking for a regex pattern which will filter a string.
If the last 2 characters are ,}
it should remove the ,
from the string.
Example:
helloworld,}
//^
should become
hellworld}
//^
If you insist on regex, you can use positive look ahead as
preg_replace('/,(?=}$)/', '', "helloworld,}")
// helloworld}
Regex Explanation
,
Matches ,
(?=}$)
positive look ahead. Checks if the ,
is followed by }
and then end of line $