正则表达式比PHP中的字符串函数更有效吗? [关闭]

Whenever I see questions regarding regex on SO, everyone says that regex is slower than string functions. Are there cases when regex is faster than string functions? Or is regex purely for convenience?

Since PHP is an interpreted script language, solving your problem using the least code possible is generally the most performing way of achieving what you want. And since regex is built-in, it should run much faster than any script despite of the complexities involved in its algorithm.

But naturally comparing both will depend on how complex it would be to mimic your regex in pure PHP code, so the answer to your question cannot be generalized. It will depend on each specific case.