r/ModSupport • u/nerdshark • Jun 26 '24
Admin Replied Post Guidance - invalid regex error when using example rule
I'm trying to use this example post guidance rule verbatim in our post guidance config, and am getting the error
regex condition(^(.|\s){3000}.+) was invalid
when I try to save it. Changing 3000 to 1000 works. Can I get clarification on why the input length restriction is so low, and how we can work around this? Thanks.
Edit: I just realized this is literally the same issue we had two months ago. We got a modmail saying that regex lookaround was being disabled in post guidance, but none of our rules used it. What did get flagged were our rules catching giant walls of text:
https://i.imgur.com/hegpH1I.png
Notice the use of large repetition quantifiers (the{3000}) in both the example rule and the rules in my screenshot. So, what's going on? Is the example in the post guidance docs correct and supposed to work? The page is one day old, so I can't imagine that the examples weren't tested. Or have things changed and gone undocumented?
Edit 2: I found a workaround, at least for this use case. Instead of checking for 3000 characters at once, do three consecutive checks for 1000 characters:
^(.|\s){1000}(.|\s){1000}(.|\s){1000}.+
This is less readable and that annoys me, but at least it works. I'm still interested in hearing from the admins about why they set limits this low, and why the example rules they're providing aren't being tested first.
1
u/Laymon_Fan Jun 27 '24
I'm not sure what you're trying to do.
If 3,000 is too high for Reddit's system, just try some other numbers between one thousand and three thousand. 🙂
'^(.|\s){,3000}$' should expect a maximum of 3,000 characters.
'^(.|\s){,3000}(\.)+' should expect a maximum of 3,000 characters plus at least one period.
'^((.|\s){,1000})+' expects one or more chunks of up to 1,000 characters each.
My guess is that you need a comma before whichever number you pick. (1000, or whatever)
(If you'd like to set a minimum number, you can include that before the comma: {1,1000} )
But I've been using regex only for the Automod — I use plain keywords for my automations — so I can't even figure out what you're trying to do. 😄
2
u/nerdshark Jun 27 '24 edited Jun 27 '24
No, the regex is valid. I've tested it elsewhere. I'm asking the admins specifically about a change they made to disable regex lookaround that also unnecessarily restricts the length of text some regex operations can work on.
This particular regex is meant to limit posts to 3000 characters or less. It's one of the reddit-provided examples, and I tried using it verbatim. And it doesn't work. I'm trying to get clarification on what changes they made that broke this.
1
u/Laymon_Fan Jun 27 '24
You could avoid using regex altogether.
--- type: submission body_longer_than: 3000 action: remove action_reason: The post is too long. comment: Your post was removed because it exceeds 3,000 characters. ---You could also replace
commentwithmessage.Of course, that's an automoderator rule, not an automation, so the user wouldn't get a warning message as he was typing.
→ More replies (3)
2
u/PossibleCrit Jun 27 '24
Hey nerdshark!
It looks like this is actually a limitation of the regex engine:
Implementation restriction: The counting forms x{n,m}, x{n,}, and x{n} reject forms that create a minimum or maximum repetition count above 1000
We've updated our own documentation example to reflect this.
2
u/esb1212 Jun 27 '24
Try posting in r/AutoModerator, people there are more knowlegeable in regex.