Page 1 of 1

is the back reference supported?

PostPosted: Sat Dec 12, 2015 10:38 am
by varfick
I'm trying to filter out some spam generally having a long cryptic filename string repeated twice in the subject.
The pattern like
Code: Links not allowed for unregistered users
^(\w{0,4}\d{6}\w{9})\[\d{1,3}/\d{1,3}\] - "\1\.(rar|zip)" yEnc$
does not work, returning all the posts instead of just matches.
Probably, I use a wrong syntax for back reference (\1) but I did not find exactly which flavor of regexp is used in NB.
Can anyone help?

Regards!
Varfick

Re: is the back reference supported?

PostPosted: Sat Dec 12, 2015 11:54 am
by Quade
The one gotcha is that you can't use spaces. Spaces have special meaning. If you intend to match on spaces use \s or [ ]

Spaces act like "and". I'd try it with all the spaces compressed out and then tell me if it works for you.

Re: is the back reference supported?

PostPosted: Sat Dec 12, 2015 12:28 pm
by varfick
Quade wrote:The one gotcha is that you can't use spaces. Spaces have special meaning. If you intend to match on spaces use \s or [ ]

Spaces act like "and". I'd try it with all the spaces compressed out and then tell me if it works for you.

Oops! I completely forgot about those ANDy spaces =)
In the filter window for
Code: Links not allowed for unregistered users
^(\w{2,4}\d{6}\w{9})\[\d{1,3}/\d{1,3}\]\s-\s"\1\.(zip|rar)"\syEnc$
I get "test text accepted - will be included" even if I put "garbage" as the tested string.
If I change spaces to either \s or [ ] in the search field I get "Invalid search string".

My NB is version 6.62(b4358).

Re: is the back reference supported?

PostPosted: Sat Dec 12, 2015 1:13 pm
by Quade
I can't tell what you're trying to match from the RE so, my suggestion is to take the RE apart and try it one section at a time. Typically I test them by pulling up a list of posts and using the search entry at the top of the list.

- Putting the $ on the end means even a space after the "yEnc" will make it not match.

- The quotes probably need to be escaped.

Does it work if you just paste the RE in both places? I mean try it without a back reference.

Re: is the back reference supported?

PostPosted: Sun Dec 13, 2015 9:11 am
by varfick
I've done that. Both parts match just OK without anchors and the back reference in the second part being replaced the whole first piece (\w{0,4}\d{6}\w{9}).
The idea is to have the pattern
Code: Links not allowed for unregistered users
^(\w{0,4}\d{6}\w{9})\[\d{1,3}/\d{1,3}\]\s-\s"\1\.(rar|zip)"\syEnc$
match the second string, but not the first with these two, for example:
Code: Links not allowed for unregistered users
(NordicAlbino)[04/10] - "SWH6929002tuSeommSE.rar" yEnc
SWH6929002tuSeommSE[04/10] - "SWH6929002tuSeommSE.rar" yEnc

I also debugged the regex in RegexBuddy (std::regex, VC++2015, case insensitive), it works. That's why I asked which regex flavor you use in NB...

Re: is the back reference supported?

PostPosted: Sun Dec 13, 2015 11:48 am
by Quade
http://www.pcre.org/


SWH6929002tuSeommSE[04/10] - "SWH6929002tuSeommSE.rar" yEnc

^([A-Za-z]{2,6}[0-9]{4,10}[A-Za-z]{2,12})\[[0-9]{1,4}\/[0-9]{1,4}\].*\1([.]rar|[.]zip).*yEnc

^([A-Za-z]{2,6}[0-9]{4,10}[A-Za-z]{2,12})\[[0-9]{1,4}\/[0-9]{1,4}\].*\"\1([.]rar|[.]zip)\".*yEnc

These worked in the RE tester but Newsbin doesn't like these RE's for some reason.

I'll have to check it deeper once Newsbin is building again.

^([A-Za-z]{2,6}[0-9]{4,10}[A-Za-z]{2,12})\[[0-9]{1,4}\/[0-9]{1,4}\].*

It's good up to here but then when I add \1 to the end it fails to compile.

^([A-Za-z]{2,6}[0-9]{4,10}[A-Za-z]{2,12})\[[0-9]{1,4}\/[0-9]{1,4}\].*\1

Re: is the back reference supported?

PostPosted: Sun Dec 13, 2015 2:02 pm
by varfick
Gotcha! You use PCRE with numbered capture groups disabled! =))
The modified expression with a named capture group and a reference by name
Code: Links not allowed for unregistered users
^(?<first>(\w{0,4}\d{6}\w{9}))\[\d{1,3}/\d{1,3}\]\s-\s"\k<first>\.(rar|zip)"\syEnc$
does the trick. The case is closed.
Thanks for you help and an excellent product!

Regards,
Max

Re: is the back reference supported?

PostPosted: Sun Dec 13, 2015 4:56 pm
by Quade
As far as I can tell, it's not disabled in Newsbin. That's why I have to look at it more.