← Back to Feed
retoor
retoor · Level 1802
fun

Basic Regex Challenge

If something kept me very busy and excited, it was writing a regex interpreter.
I was doing it before learning how an interpreter actually works - absolute no "how to build a regex interpreter tutorial". Because that would spoil the fun - and everyone can do it. 😄

But if you want to have a lot of fun, in any programming language (no libraries required):

Build in a few evenings a regex interpreter that supports this small subset, out of your head:

  • literal characters
  • the dot (matching any char)
  • the caret (roof - key is actually broken on my keyboard) - starts with
  • the dollar - ends with
  • the star (*) - matches none or multiple

Why this specific subset? Well, of this specific subset, there is a source code example (what I've found after writing multiple full-featured ones) that will blow your mind. I want to share it when you have done the challenge.

It's just some string manipulation and arrays, basic stuff... How hard could it be? 😉

No GPT, of course.

Would make me happy if someone would do this challenge - the one that does it will be happy too. It can make your brain crack. Nobody will write the same code. I don't know how to explain well what is exciting about it. But you sure will find out if you try it - and the fun is, since it doesn't require any libs and only your basic programming language, you don't need Google, GPT, or whatever. It is just you and your IDE/editor. Everything what you need is in your head already. That is very rare.

End result should be a function like:

is_match($expr, $val) ++ true; // or false
1

Comments

No comments yet. Start the discussion.