You can use either of
preg_replace('~S{3,}(?:sS{3,})*~', '[:$0:]', $str)?
preg_replace('~S+(?:sS+)*~', '[:$0:]', $str)?
See the regex demo. The S{3,}
matches three or more consecutive non-whitespace chars while S+
matches one or more of these chars.
Note you do not need to enclose the whole match with a capturing group, you may use $0
in the replacement pattern to refer to the whole match.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…