Asking chatGPT to create a regex

Here is the story...

I have asked chatGPT to create a regex which selects words from a text file which:

  1. Start with capital letter
  2. Doesn’t contain digits
  3. Doesn’t contain “w” character neither in upper nor in lower case
  4. Ends with “e” letter.


It took 3 iterations of “failure-correct” before it created the one which passed my test

First one was:

"\\b[A-Z][a-zA-Z]{4,}[a-df-zA-DF-Z]\\b"

Many words containing “w” appeared in the output

Second attempt by chatGPT:

"\\b[A-Z][a-zA-Z]{4,}e\\b(?!.*[wW])"

Word “Workmate” passed throw

Third attempts by chatGPT:

"\\b[A-Z][a-zA-Z]{4,}e\\b(?!.*[wW])"

Which seems exactly the same as the second one

The fourth attempt:

"\\b(?!.*[wW])[A-Z][a-zA-Z]{3,}e\\b"


Finally it passed my test input.txt file, but how can I be sure it will not fail on some other set of input data?

Many people think that AI will replace programmers, but I personally think that it could be a powerful tool in the hands of good programmers instead. The same happened to Chess about 30 years ago, everyone said that Fritz, ChessMaster and others will replace human chess players, but we still have them, still humans play chess.

Wouldn't you agree with me here?


Kirill Shiff

Senior Full Stack Java Developer

1 年

Did you used chatGPT 3.5 or 4?

回复

要查看或添加评论,请登录

社区洞察

其他会员也浏览了