Next time you’re trying to write some regex, check out regex.help - it should make your task much easier. A couple of weeks ago, after Secretwords was finished, a colleague pointed me towards
grex. It’s a really neat tool to help you write regex.
The main idea is that you provide a couple of examples of the text you want to match and
grex spits out a pattern matching all of them.
Usually, the way you write regex is probably something like this:
- have one or more examples of the thing you want to match in your head,
- write a regex that you think might match them,
- try it out,
- find out it’s wrong, fix it and try again.
This is fine and there are many tools already, which help you get there. However, with grex you can skip a step:
- enter one or more examples of the thing you want to match,
- you now have a regex and it’s correct (!!!),
- it’s likely not exactly what you want though, so you can still iterate.
I think this is pretty neat. Since I’m currently in the Elixir/Phoenix/LiveView honemoon land, this also gave me a chance to play with
rustler, which is an Elixir library allowing you to embed some Rust code. I was very pleasantly surprised how easy it was to plug it all together.