+1, although... @user1518659 FYI:
preg_quote()
is a bit of a carpet-bomb approach to the escaping here. The only characters that need to be escaped in a character class are
^\]-
and the delimiter, a caret only needs to be escaped if it is the first character in the set and a hyphen only if failure to do so would indicate a character range. However, what has been done above will still work fine, and I think this is probably the best approach from a readability and maintainability perspective. —
DaveRandom 4 mins ago