38

I came across an answer that includes a regex generated with an AI-powered regex generator.

Does that qualify for removal under Temporary policy: Generative AI (e.g., ChatGPT) is banned?

The OP has freely admitted usage of the above mentioned website, applying heuristics and whatnot here is beside the point. Notably, the post doesn't include text that appears AI-generated beside the regex itself.

The tricky part here is, there are plenty of tools that help with generation of expressions, be it regex (https://regex-generator.olafneumann.org) or cron (https://crontab.guru/) and many others.

However tools such as the one used for that answer are AI-powered. I'm not sure if that is much different from asking [insert LLM here] and copy-pasting only the actual expression out of the full response. (As a matter of fact, the mentioned website is probably just a wrapper around some LLM.)

The post is the following (temporarily locked to prevent Meta effect):

16
  • 9
    I always thought the reason AI was banned is because (a) it results in too many good-looking but bad quality content that our content-curators can't keep up with it and (b) content license issues. I'm not sure if (a) is a problem (yet) with AI Regex and we could solve (b) as with any other copied content, by providing attribution and quoting the content. Commented Mar 27 at 14:26
  • 1
    In my opinion, if a carbon-based neural network is allowed to post, then we shouldn't be prejudiced.
    – Ian Boyd
    Commented Mar 27 at 14:28
  • 15
    Does it speak for AI or against regex that this looks just like any other regex answer? Commented Mar 27 at 14:39
  • 13
    It's no different from using chatgpt to generate a line of code.
    – Kevin B
    Commented Mar 27 at 14:42
  • 6
    It would be nice to leave some of these answers around to get the word out. If the thing actually works well, and I don't know why it would so I'm skeptical, it could move a lot of regex questions off the site along with the tears and agony surrounding that tag. Commented Mar 27 at 14:46
  • 1
    Is the quality of the answer subject or relevant here? I'm no one kotlin expert, but the characters range captured by AI regular expression, kindly speaking, doesn't seem to match the captured characters range by 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? Commented Mar 27 at 16:54
  • @AugustoVasques The regex matches as desired: The \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. Commented Mar 27 at 16:59
  • 3
    @MisterMiyagi, The \w regex captures a smaller range of characters than the isLetterorDigit() 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 is CharCategory.UPPERCASE_LETTER, CharCategory.LOWERCASE_LETTER, CharCategory.TITLECASE_LETTER, CharCategory.MODIFIER_LETTER, CharCategory.OTHER_LETTER, and number being CharCategory.DECIMAL_DIGIT_NUMBER which are UNICODE categories of characters. Commented Mar 27 at 17:09
  • 2
    @AugustoVasques Ah, sorry, I’m used to regex engines with implicit unicode support. No idea how Kotlin handles this. It would certainly be interesting if the answer were to discuss this - though the absence of any mention does not raise confidence in the author actually knowing. Commented Mar 27 at 18:06
  • 1
    (Super not the point, but regex-generator.olafneumann.org is really neat and I'd never seen it before, so thanks for introducing me to that)
    – zcoop98
    Commented Mar 27 at 22:50
  • Maybe we should close those questions instead...
    – Braiam
    Commented Mar 28 at 0:14
  • 6
    It's interesting that the linked regex generator only asks for one example of text that should match and zero examples of text that should not match. Even a human would have trouble writing a regex that solves the asker's actual problem without more information. Commented Mar 28 at 0:58
  • 1
    Aside from the discussion about banning, shouldn't the answer be marked as spam? "It's so easy to use. Just enter your criteria and that's it." sounds very spammy to me. Commented Mar 28 at 8:20
  • 5
    @OcasoProtal yes, in this particular case, it should. As soon as this discussion is over, that post will be removed as spam.
    – blackgreen Mod
    Commented Mar 28 at 8:33
  • @PresidentJamesK.Polk what word we are trying to get out? That AI writes code and makes devs obsolete. That one is out already. That hype trian has so many passengers.
    – M--
    Commented Mar 29 at 2:07

5 Answers 5

46

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.

8
  • 1
    I'm less swayed by this because you've used two examples that are pretty classic "RegEx traps", which are essentially unwinnable queries... I don't intend to defend it as a great tool or anything, but I don't think your examples are very compelling.
    – zcoop98
    Commented Apr 3 at 15:09
  • 3
    @zcoop98 i mean... is it a trap, if it's literally the example they provided as a placeholder in the prompt input?
    – Kevin B
    Commented Apr 3 at 15:11
  • 1
    I also strongly disagree that "the documentation says I can trust it" qualifies as "wrong with confidence". The GenAI ban announcement talks about answers being wrong but "looking" right– this, on the other hand, looks no more right than any other RegEx expression or answer, which I don't feel falls into the same category. Again, my point isn't that this generator is "good"– it's just that I hesitate to consider this as in the same category as GenAI chatbots targeted with the ban. I also don't think tying our rules to the quality of the tools' output is very robust.
    – zcoop98
    Commented Apr 3 at 15:16
  • @KevinB That's definitely fair enough; I'm more wanting to get at the idea that gauging the usefulness of any tool by setting it up to fail doesn't produce very useful data. I think that's true even if the tool is genuinely crap, which I don't intend to dispute about this particular one.
    – zcoop98
    Commented Apr 3 at 15:18
  • @zcoop98 I'm guessing this specific tool (the one in the now spam deleted answer) is just a particularly bad example. i don't do much regexp so can't really comment on the true usefulness of it, but i certainly agree there's tools like this that actually do produce good results for a specific purpose. There's just a ton more such tools that claim to but are just complete garbage, on a "Give me your email and i'll tell you your fortune" level.
    – Kevin B
    Commented Apr 3 at 15:22
  • 1
    @KevinB Anything that uses a language model to do a job that requires a parser to do properly is going to be crap. Some (like this one) are just more obviously crap than others. A good tool happens when someone understands the problem, understands the techniques, and uses an appropriate technique in the right way. cdecl.org has been correctly translating English to code just fine for the last 15 years. If you give it a query it can't answer, it doesn't give an incorrect response; it says "Syntax error".
    – Ray
    Commented Apr 3 at 16:37
  • 2
    (I hate that I always have to be the voice of caution on this stuff: transformers (and attention mechanisms in general) are amazing at the job they actually do. I just wish people would stop waving them like a magic wand at every single problem without even trying to understand the underlying math.)
    – Ray
    Commented Apr 3 at 16:37
  • @zcoop98 "this, on the other hand, looks no more right than any other RegEx expression or answer" That's because good regexes also look like line noise. :-)
    – Ray
    Commented Apr 3 at 16:44
20

How would you react if the answer had said something like "I created this regex by using a Python script from my personal projects folder" (without showing any of that code, or explaining why a script would be necessary or helpful for creating the regex, or explaining why the regex is too complex to reason about manually)? That would simply be noise, right? It doesn't explain anything about what the regex does; it contributes nothing to answering the question.

Now, what if the claim was instead that the tool was some proprietary online software - not AI powered, but also not shown? That still isn't saying anything useful - anything explanatory - about the regex. In fact, given phrasing like

I use [link] for [this task]. It's so easy to use. Just [do something simple] and that's it.

... well, I would be considering a spam flag, and I wouldn't blame others for doing the same. It looks an awful lot like an attempt to promote the [this task]-completion service provided at [link], doesn't it?

So of course adding even a whiff of AI to this is certainly not helping matters. If the author of the answer understands the regex, then at best there is no point in adding any of this. It's not a meaningful attribution (using a computer program isn't "research", and there is no author to credit), so avoiding plagiarism isn't relevant. But for well-meaning users, I would prefer to give the benefit of the doubt: edit out the noise, and offer a link to How not to be a spammer, just in case OP has some undisclosed affiliation to [link]. After all, the question didn't even ask for a regex; it asked for a way to test strings for certain criteria. (I think it Needs More Focus, honestly.)

But if the answer's author doesn't understand the regex, then the "explanation" offered is either output from the AI tool or (far more likely, at least in this case) a prompt that was offered to the AI. Either way, it's a pretty clear violation of AI policy. The only informational content here is "this sounds like a job for a regex™"; anyone who wants an AI to generate a regex could just go do that instead of asking someone else on Stack Overflow to do it.

7
  • 4
    It is only meaningful, if it's a reasonable admission of not knowing whether or not the regex (or line of code) is correct. The context around the line can certainly provide clues about that, but if our policy is literally no generative AI, then an admission of posting content by generative ai is clearly against the policy. would we care if they hadn't told us? probably not. We also don't care about someone being underage until they tell us.
    – Kevin B
    Commented Mar 27 at 19:49
  • 3
    Your statement that plagiarism is not a relevant concern is incorrect (even for a non-AI proprietary tool). On Stack Exchange, anything that is not your own, original content must be cited. Both this instance and your hypothetical example are definitely instances of "copying content from [...an...] online [...] tool" so not following our referencing standards would be a violation of the CoC under the "Inauthentic usage policy".
    – Henry Ecker Mod
    Commented Mar 27 at 20:03
  • @HenryEcker What if there is no way to create a permalink for the specific output used in the answer? Commented Mar 27 at 20:15
  • the deciding factor of how you suggest us to act is "if the answer's author doesn't understand the regex". unfortunately, I am not telepathic, and almost nobody (especially anyone trying to farm rep) will say "I got this from an AI and I have no idea what it means"... how would you decide which option to take (edit vs flag) then?
    – starball
    Commented Mar 27 at 21:06
  • @starball the main point of my answer is that the content shouldn't be in the answer either way. Regarding the flag, I don't have a strong opinion. Commented Mar 27 at 22:30
  • 2
    @KarlKnechtel Like all other sources where a direct link is not possible (like offline sources) the guidance is to "include the source to the best of your ability". In this case, I would think that the "best" would include the name of the tool used (and/or a link to it) in addition to the prompt used to generate the response. Both components being necessary to (re)create the same (or similar) "source" material.
    – Henry Ecker Mod
    Commented Mar 28 at 22:49
  • 3
    Having said that, however, this community hasn't gone through any conversations about how GenAI content needs to be attributed to follow the referencing standards because we've disallowed it (within the confines of the established heuristics) wholesale. There may be other network communities who have a more formalised understanding of what "properly cited" GenAI looks like.
    – Henry Ecker Mod
    Commented Mar 28 at 22:49
10

I think in cases like this, if an author admits their code was generated by an AI, that's no different from what's currently banned under the Temporary Policy banning generative AI:

All use of generative AI (e.g., ChatGPT and other LLMs) is banned when posting content on Stack Overflow.

So we should delete this content.

There are at least some mods (maybe most?), however, who don't apply that rule as written, and only apply it to questions written wholesale by AI. So I guess you have to come to a group consensus on that, first, if there is dissent about whether this counts.

14
  • 6
    FWIW, I haven't brought this up internally. It's such an edge case that I wanted to prioritize the broader community input.
    – blackgreen Mod
    Commented Mar 27 at 15:07
  • btw, I don't quite understand what you mean with "some mods [...] who don't apply that rule as written, and only apply it to questions written wholesale by AI"
    – blackgreen Mod
    Commented Mar 27 at 15:07
  • 6
    I mean the policy as written bans all use, which includes "I used a genAI tool to generate this code to start with" or "with the help of AI [...]". But there are answers on Meta that suggest the policy shouldn't be interpreted that way, e.g. yours here: meta.stackoverflow.com/questions/426915/… Despite numerous users and other answers pointing out that conflict w/ the wording of the policy, the policy and the conflicting guidance about it both remain unchanged.
    – TylerH
    Commented Mar 27 at 15:16
  • (Note, that isn't the only case where the site rules state one thing but mods regularly interpret them to mean something else--the other main culprit probably being NAA flags).
    – TylerH
    Commented Mar 27 at 15:17
  • Regarding that specific post you mention, if you are a member of the GenAI Team, you can find an additional important piece of the conversation which I won’t repeat here. As for NAAs, if you have specific concerns or if you think a flag has been mishandled you should bring it up in Meta so that it can be properly reviewed
    – blackgreen Mod
    Commented Mar 27 at 17:38
  • @blackgreen I'm just addressing your question, not pointing to specific case examples that need to be addressed at the moment. My answer refers to process issues, not specific cases.
    – TylerH
    Commented Mar 27 at 18:10
  • 1
    Ok, I still don’t understand the sentence “only apply it to questions written wholesale by AI”. Are you saying that there are mods who arbitrarily don’t delete AI-generated posts (beside the controversial issue you linked earlier)? What I understand from your words is that “only questions written wholesale by AI” are moderated in a consistent fashion, and that’s definitely not my impression
    – blackgreen Mod
    Commented Mar 27 at 18:18
  • 3
    @blackgreen I'm arguing that this question you've posed above about how to handle AI-generated regular expressions shouldn't need to be asked in the first place because it involves using AI, and the current site policy bans all use of AI in posts. It's only necessary because at least some (I say "at least some" because ostensibly it has to be at least one, not necessarily any specific moderators or number of moderators, otherwise we wouldn't be discussing this) apparently consider the policy to mean something less/something more constrained than what it actually says.
    – TylerH
    Commented Mar 27 at 18:26
  • 10
    The policy does not say "all use of generative AI, except for generating code snippets as a basis and then writing a question or answer from there, is banned when posting content on SO". It says "all use of generative AI in posts is banned when posting content on SO".
    – TylerH
    Commented Mar 27 at 18:28
  • 1
    My question here is not really about whether the policy bans AI or not. It does, we all know that. The question is more like whether AI-powered tools that aren’t LLMs fall in the same basket. My personal opinion is that it does fall in the same basket, but it’s an edge case, open to interpretation, on which it’s worth to gauge community consensus.
    – blackgreen Mod
    Commented Mar 27 at 21:32
  • 2
    I mean... do we know it isn't an LLM? it definitely seems to act like one, providing a variety of different answers if you try repeatedly with the same prompt.
    – Kevin B
    Commented Mar 27 at 21:35
  • 2
    I think it's probably more useful to consider whether this should be banned, rather than just interpreting the current policy. With community consensus, the policy (or interpretations of edge cases or ambiguities) can change.
    – Ryan M Mod
    Commented Mar 27 at 21:45
  • @RyanM I mean, i agree, but the important bit to whether or not I think it should be banned is whether or not it can be trusted... and if it's just dumping LLM output on the page and can't accurately explain what the regex is doing or why it's the solution or even accurately state whether or not it is correct (the site even tells you not to trust the output!) then it shouldn't be allowed. The common factor between this solution and more deterministic ones is this one just guesses.
    – Kevin B
    Commented Mar 28 at 3:16
  • @KevinB Whether it is an LLM is not really relevant, it is generative AI (it claims to be AI, and it generates code), and thus is banned ("e.g." means "for example", so the current phrasing of the ban doesn't imply that only use of LLMs are banned) Commented Mar 28 at 9:57
8

Should usage of AI-powered regex generators be banned under the temporary policy?

Yes, the use of AI-powered regex generators should be banned.
Specifically, it's AI-generated content insertion what is already is covered by the ban, that constitutes:

  1. Plagiarism because it is not possible to trace or identify both the origin and the author of the content spewed by AI.
  2. Spamming by citing the tool that generates the regular expression as if it were an advertising piece indicating as a solution something other than what was requested in the question without a justification or even an objective attempt to adapt the questioner's scenario.

I'd like to add that the ban on AI-generated content is not unfair and the answer in question here itself shows how fragile AI's knowledge-building mechanism still is compared to the human brain.
As I've already said, here and here, I'm not a Kotlin expert. I'm just the guy who picked up the manual to read and understand a bit more about the problem, and looking at the problem more closely, I identified a flaw in the analysis of the AI tool whose ignored by the author of the answer in question.

It seems to me that, due to the way the Kotlin language works with regular expressions, there is a big difference between what is asked in the question on the main site and what the AI has answered.
In the question, the user employs the isLetterOrDigit() function as a character validation function, while the AI generated a solution based in \w regex(word character) to emulate isLetterOrDigit() function behavior.
The problem is that the regular expression \w does not capture the same range of characters as the isLetterOrDigit() function, it's a freak simplification that AI makes, you see:

  1. Both in build code for JVM or JavaScript platforms, the \w regular expression captures just [a-zA-Z_0-9] characters range. (In JavaScript, regex are constructed with the u flag that enables Unicode-related features in regular expressions, but the gap is still there.)

  2. isLetterOrDigit() function considers a wider range to be a letter if its category is

Note:
According as explained here, under Java, Kotlin uses Java's regex engine, where \w will support Unicode range if you enable the UNICODE_CHARACTER_CLASS flag or U flag, and under JavaScript, Kotlin regular expression are Unicode aware by default. See kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/-regex.

7
  • 2
    This is an excellent answer, it highlights the exact flaw in AI generated answers, context. A human would understand the difference between isLetterOrDigit() and /w, while an LLM, conclusion that isLetterOrDigit() == /w while indeed correct on a subset of characters is actually false in other instances. What you end up with is an answer that is factually correct, except without the knowledge to fact check the answer, is completely and totally useless. It's factually correct in that /w can be used, and will work in the majority of cases, but is not a viable solution for others. Commented Mar 27 at 23:05
  • 3
    @SecurityHound it's hurts my brain so much that your slash is in the wrong direction
    – starball
    Commented Mar 27 at 23:49
  • @starball - I copied and pasted isLetterOrDigit() and typed \w, I am all out of aspirin tonight, had to empty the bottle due ending up having to do my contractor's job Commented Mar 28 at 2:13
  • 1
    plagiarism in regex? that's a new one. +1 for originality
    – NickNo
    Commented Mar 28 at 2:28
  • 1
    @NickNo. I considered it plagiarism in the sense that the user didn't build the solution and the AI didn't build it either. It was a copy of text generated by something that was copied from existing content on the web that someone had put some effort into creating and the source was't mentioned. Commented Mar 28 at 7:05
  • 1
    Under Java, Kotlin uses Java's regex engine, where \w will support Unicode range if you enable the UNICODE_CHARACTER_CLASS flag (or (?U)), and under JavaScript, Kotlin regexes are Unicode aware by default, see kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/-regex. Commented Mar 28 at 9:56
  • @MarkRotteveel. Thanks for the clarification. I'll add the information to the answer as soon. Commented Mar 28 at 15:21
1

It should not be banned.

To explain my reasoning, I need to go back to the reason why we banned LLM-generated text. The primary problem with LLMs is that they make it hard to evaluate the quality of answers. LLMs make it too easy and tempting to generate crap that looks like non-crap. This is because LLMs generate text that has the superficial indicators of quality, but where the actual content often has errors -- often, hard-to-spot errors. This overwhelmed the capacity of human reviewers to evaluate answers and apply our quality standards. We needed a solution to that problem.

That doesn't apply to this situation. I see no evidence that AI-powered regexp generators create regexps that are harder for voters to evaluate than regexps created by other non-AI tools. I also see no evidence that AI-generated regexps are harder to evaluate than human-written regexps. AI-generated regexps don't have the superficial indicia of quality -- e.g., a confident and authoritative tone of voice, proper spelling and grammar, reasonable-sounding structure, etc. -- that LLMs do. These AI tools don't create a serious danger of being overwhelmed (any more than we already are).

Ultimately, it's not the same problem as LLM-generated text. Consequently, I suggest that answers that contain regexps generate with the assistance of AI shouldn't be flat-out banned by policy.

Voters should still feel free to upvote or downvote such answers as they see fit. In this particular case, it sounds like the tool generated a poor regexp. I think the appropriate remedy is to downvote the answer. I want to warn that 'hard cases make bad law', e.g., from looking at one example of a bad answer, it's tempting to react by saying "we don't want that" and be moved towards a policy of banning it. I also recognize the quite appropriate bad feelings towards use of GenAI in answers overall, and it's hard to not let that affect our reaction to this situation as well. But I sincerely believe that the best policy for this community is to do nothing about AI-generated regexps, at least for now. We can revisit and evaluate the situation if it becomes a widespread problem or there is evidence that action is needed, but right now, I recommend that they should not be prohibited by policy.

3
  • 1
    I think this is a really important point; the AI policy is an escape hatch; a stopgap policy to handle an exceptional influx of a specific kind of garbage that our existing tools are not prepared to handle. AI-generated RegEx doesn't seem, to me, to fall into this same gap, largely because they take an exact, measurable, curatable form: RegEx expressions. While the expert-sounding prose of a GenAI LLM clearly make generated wrong answers harder to moderate, I do not see the same correlation with these RegEx patterns, so unless the volume is very high, banning outright feels excessive.
    – zcoop98
    Commented Apr 3 at 17:25
  • This is reasonable, in principle, although it doesn't make for a strong policy. You are saying: "don't ban if we can easily assess it" but the definition of easy here varies wildly among SO readers. We're back at square one where AI is banned because there isn't enough Subject-Matter Experts able to curate AI-generated content in a timely fashion.
    – blackgreen Mod
    Commented Apr 4 at 8:25
  • 1
    @blackgreen, I'd frame it differently. I'd say: "a ban requires a strong justification (lacking any strong arguments either way, the default is no ban) and there is not a strong justification here (there was a strong justification for LLM-generated text, but those reasons do not apply to AI-generated regexps)". As far as I can see, curating answers containing AI-generated regexes is not significantly harder than curating answers containing regexes generated by non-AI tools, or curating answers containing regexes generated by humans.
    – D.W.
    Commented Apr 4 at 17:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .