vendredi 31 juillet 2015

PCRE regex to remove empty braces

How can one write a regex to remove all pairs of braces that contain nothing?

For example, {} and {{}} should be reduced to an empty string, but {{} becomes { and {{A}{}} becomes {{A}}.

I'm currently running s/\{\}//g in a loop until the string length is fixed, but is there a better way to do this?

Aucun commentaire:

Enregistrer un commentaire