Consider the following string:
I have been driving to {Palm.!.Beach:100} and it . was . great!!
I use the following regex to delete all pun
$str = preg_replace('(\{[^}]+\}(*SKIP)(*FAIL)|[^a-zA-Z ]+)', '', $str);
See also Split string by delimiter, but not if it is escaped.
Try this
[^a-zA-Z {}]+(?![^{]*})
See it here on Regexr
Means match anything that is not included in the negated character class, but only if there is no closing bracket ahead without a opening before, this is done by the negative lookahead (?![^{]*})
.
$string preg_replace('/[^a-zA-Z {}]+(?![^{]*})/', '', $string);