Why Rust doesn't include the regular expression library as the standard library?

So I'm new in Rust. I want to try Rust to solve some programming question in codeforces and I have to use the regular expression to solve it. I have try to look for the regular expression but as far as I know, Rust doesn't have any built in regular expression, people have to use the external library like https://github.com/rust-lang/regex so I abandoned my intention to use Rust.

Why Rust doesn't include the regular expression library as the standard library? Is there any plan to make it as the standard library?

1 Like

regex being an external library changes nothing about what it's capable of, the quality of the code, or how you'd use it. It allows the library to update independently of the rest of the language and compiler. The language and tools have all been designed around pushing as much functionality out of the standard library as possible.

The standard library doesn't include regular expressions because there's no compelling reason for it to do so.


Further to this, the Rust ecosystem is a little different to others you might be familiar with, where there are practical impediments and complications to pulling in additional library components. Cargo and crates.io integration is such that it is basically no harder to use additional libraries. This is intentional, and as noted, allows the whole ecosystem to evolve more rapidly as well as making development easier.

Basically, there is generally much less importance on whether or not some bit of code is "part of the standard library".

Now, there can still be some other very important considerations involved in using third-party code beyond simply how to get it on your machine and linked into your build, but those are generally relevant to specific projects, policies, and particular environments; they're much less important for initial learning and exploration.

However, for learning, I have heard also that some of the online tutorial platforms don't facilitate using external crates. In some cases it may be deliberate because the point of the particular exercise is to solve the challenge directly with your own implementation, in other cases I suspect it may be more to do with the platforms having assumptions carried over from other languages. I don't know if that's part of your reason for asking the question, but it won't be part of any consideration about whether regex (or anything else) gets added to std.

And if you do need crates online, remember that you can use the top 100 crates on the playground -- including regex: Rust Playground

1 Like