Hacker News new | ask | show | jobs
by da_chicken 1678 days ago
> Why use it though?

Because a well written regex performs extremely well (regex engines are often very highly optimized).

It gives you all the benefits of using a domain-specific language and using an extremely mature software library. Just like a domain-specific language, it will have a baked-in philosophy involving the exact task you want to accomplish, so it will not suffer from language vs algorithm impedence. Just like using a mature library, it will probably have accounted for weird oddball cases that you're not even thinking of and have enough features to do everything you will want.

> It's basically an embedded BrainFuck in your programming language.

I don't disagree. It's not easy to read and can be hard to maintain. There are ways to write regex such that it's easier to understand, but the syntax generally doesn't make it easy to do that and doesn't encourage you to spend the time on it.

However, when you see a regex, you do know that it's 100% used to manipulate strings. That alone tells you quite a bit about what is going on.