I am creating rules for a reddit automoderator. It gets its rules from a YAML config file and the regexes are interpreted as Python regex.
I am trying to make the following regular expression work:
(https?://[\\w\\d:#@%/;$()~_?+-=\\.&]+\\.\\w{2,6})([\\S\\s]*\\1)
When I test it on https://pythex.org/ it works perfectly to achieve what I want.
Unfortunately my group reference at the end of the expression is causing an error when I copy the same regex into the config file:
Generated an invalid regex for
body (regex): cannot refer to an open group
I have also tried this version with everything escaped just to make sure that the characters weren't interfering in any way:
(https?://[\\w\\d\\:\\#\\@\\%\\/\\;\\$\\(\\)\\~\\_\\?\\+\\-\\=\\.&]+\\.\\w{2,6})([\\S\\s]*\\1)
But I still get the same error. Does anyone know what I'm doing wrong here?
( [\S\s]* \1 )and see if it errors.)is not being seen.\1at the end, as a test.((https?:\/\/[\w\d:#@%\/;$()~_?+\-=\.&]+\.\w{2,6})([\S\s]*\1)Note that you have to escape the dash in the class if you want it to be literal\-