How to let regex ignore everything between brackets?

前端 未结 2 1156
渐次进展
渐次进展 2020-12-17 16:50

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

2条回答
  •  抹茶落季
    2020-12-17 17:35

    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);
    

提交回复
热议问题