Weedpacket;10889075 wrote:It's precisely small tasks like this for which regular expressions are overkill. By your argument one would never use strpos, substr, trim, or strspn because either it's either such a small task that it wouldn't make any difference (and the regular expression is probably more complicated than necessary) or such a large task that it would be more legibly written as a regular expression.
In cases like this, the lag performance would be negligible. In this particular case, for a simple search through a simple string, preg wont't break the performance bank if you will.
I'm not suggesting no one use substr, str_replace or the like. If they prefer to go that route, go for it.. This is the method I would choose, overkill or not.
Sure, preg patterns run the risk of not being as well written as well as they can be a) I have more than my share of that, and
b) certainly will hurt the speed performance
But as you learn more and become more experienced, you start writing better patterns, and the differences starts to diminish to an extent (when I use the term you, I am not literally referring to you, weedpacket.. just you as in people in general).
Right or wrong, this is what I chose and offered. If the OP sees serious lag in performance as a result, then I urge going another route. It's that simple.