from Hacker News

A GPT 3.5 powered tool for generating regex

by DefineOutside on 3/30/23, 10:21 PM with 23 comments

  • by gregmac on 3/30/23, 11:01 PM

    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.

  • by BMc2020 on 3/30/23, 11:49 PM

    Rate limit reached for default-gpt-3.5-turbo in organization org-cy3MEIpOsyQxMokN4SQON5gb on requests per min. Limit: 20 / min. Please try again in 3s. Contact support@openai.com if you continue to have issues. Please add a payment method to your account to increase your rate limit. Visit https://platform.openai.com/account/billing to add a payment method.

    Ironically, it showed us the real future of AI

  • by williamstein on 3/30/23, 11:02 PM

    ChatGPT is also very useful for just explaining what a regexp you already have actually does.
  • by thomasahle on 3/30/23, 11:49 PM

    This is what is gives to select names: /^[A-Z][a-z]+(?: [A-Z][a-z]+)*$/

    I'm pretty sure quite a lot of people's names wouldn't be accepted by that. It helps if you add "even weird and foreign names", but who knows if that's actually enough to capture everything.

  • by totoglazer on 3/30/23, 10:55 PM

    Have you tried GPT-4? I suspect it would do better for these types of characters.
  • by themineraria on 3/31/23, 1:17 AM

    I think I broke it pretty badly asking for "A ll(1) grammar validator" as it answered `^(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:[A-Z]|[a-z])(?:[A-Z]|[a-z]|[0-9])):(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:(?:[A-Z]|[a-z])(?:[A-Z]|[a-z]|[0-9])):)+(?:(?:(?

    lol

    id: chatcmpl-6zxdwNH3hW7DuZqnCkx4Ukx9rXiuA token usage: 367 date: 1680225296

  • by mike_hock on 3/30/23, 11:38 PM

    > /^(?:\/(?:\\\/|[^\/\n])+\/[gimuy]{0,5}|\\[^\n]|[^\n\\\/])+$/

    What would you say was the query for this?

  • by TradingPlaces on 3/31/23, 12:08 AM

    Finally, something useful to me. If it worked. My experience was spotty in that regard.
  • by sw1sh on 3/30/23, 11:57 PM

    Is it time to revive HTML regex meme yet?
  • by sv123 on 3/30/23, 11:46 PM

    I once had a problem I solved with regex, now I have two problems.
  • by Shindi on 3/30/23, 11:04 PM

    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.