The problem with using LLMs to answer questions is that they are good at being wrong with confidence. Let's look at this tool and see how it compares:
It suggests "For email" as an example question, so we'll do that first. I repeatedly generated regexes with that prompt, and got the following responses:
\w+@\w+\.\w+
[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}
\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
The last two are just variations on the second that make some extra assumptions about boundary conditions, but the first two disagree on what constitutes an email address. (And I personally have email addresses that both will reject.)
As a comparison, https://emailregex.com/index.html suggests the following as a 99.9% solution (and has a state transition diagram to back it up):
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])
I can't validate the 99.9% claim, but that one at least accepts all the addresses I tried running against it.
Worse still is HTML. For the prompt, "For html", airegex.pro suggests the following:
\<[^>]*>
Even ignoring the "not a regular language" issue, that's just laughably bad.
So we've definitely established "wrong". Is it wrong with confidence? From the FAQ:
[Q] Can I trust the regular expressions generated by the AI tool?
[A] Definitely, The AI regular expression tool is carefully tested and validated to ensure the accuracy and reliability of the generated regex.
[Q] Is the AI Regex Tool suitable for all types of data?
[A] Yes, Tool has ability to handle wide range of data types and formats. You can try text, numbers, dates or specialized patterns. Tool can analyze and generate regular expression specialized to given specific data requirements.
Ban it.
isLetterOrDigit()
function used by the question author. I would like to know if this analysis is useful and adds value here or being left out?\w
is letters, digits, and_
. A good answer certainly should have explained that obscure part, but it's not exactly a quality standard to be expected of other regex answers either.\w
regex captures a smaller range of characters than theisLetterorDigit()
function. See the function documentation, while\w
(word character regex) captures the range[a-zA-Z_0-9]
caracteres the function in question considers to be a letter if its category isCharCategory.UPPERCASE_LETTER
,CharCategory.LOWERCASE_LETTER
,CharCategory.TITLECASE_LETTER
,CharCategory.MODIFIER_LETTER
,CharCategory.OTHER_LETTER
, and number beingCharCategory.DECIMAL_DIGIT_NUMBER
which are UNICODE categories of characters.