Live data from Hacker News

A GPT 3.5 powered tool for generating regex

fuckregex.dev

1–10 of 24 posts

Re: A GPT 3.5 powered tool for generating regex

#3
Pretty neat, and it definitely can generate some complex regex.. But I have to say I don't trust it!

When I add a regex to something, I pretty much always also add a bunch of unit test cases for it, and I request the same if I see one in a PR. It's much easier to just see a bunch of test cases that help validate than it, and frankly, half the time when I write my own cases I think of situations that could be better handled.

Human- or GPT-generated doesn't really matter IMHO; it still needs tests.

Interestingly, chatGPT is pretty good at generating test cases for regex. It would be really cool to see that functionality integrated to this tool.

Re: A GPT 3.5 powered tool for generating regex

#6
post #3

Pretty neat, and it definitely can generate some complex regex.. But I have to say I don't trust it! When I add a regex to something, I pretty much always also add a bunch of unit test cases for it, and I request the same if I see one in a PR. It's much easier to just see a bunch of test cases that help validate than it, and frankly, half the time when I write my own cases I think of situations that could be better h…

> chatGPT is pretty good at generating test cases for regex

I think this is the biggest part. Automatically generated test cases for regex will make verifying regex way easier.

Even better, when you come across some ridiculous unknown legacy regex you can ask for an explanation of it and for test cases to verify that explanation.

Re: A GPT 3.5 powered tool for generating regex

#8
post #5

If you're using a regex it's a smell that there is a better tool for what you need to do. A ton of if statements is a much more readable way of writing code than regex.

Unfortunately regex is the best we have. A bunch of if statements is also a whole less efficient and prone to errors than a regex statement. Once you start to learn regex, it actually isn't that bad. The challenging part is that a lot of people cut and paste not really understanding it and you end up with a bunch of bad regex examples.

Re: A GPT 3.5 powered tool for generating regex

#10

ChatGPT is also very useful for just explaining what a regexp you already have actually does.

There are some neat tools for visualizing a regex like https://regexper.com/

There's also regexr.com which explains in more or less plain English what's happening
Post reply on HN