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:
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?
…
Senior Full Stack Java Developer
1 年Did you used chatGPT 3.5 or 4?