Originally posted by Jesper Young:
Regular expressions are also a perfect solution for a task like this:
I agree that using a regex can easily solve this problem. However, I believe the best approach to use depends on the complexity of the problem and the context in which it is being used. There is also a significant performance overhead associated with using a regex which may or may not be an issue.
For simple searches, such as the one I demonstrated I would favour a simple approach whereas for more complex searches (ie ones that can't be handled by a few lines of simpe code) I'd definitely go with a regex approach.