>>If "searchstring" is to the right and left of an @ sign, it should 
match.

After having some time while driving a car today - my 2 cents for using a 
named  capture group and backreference ?<match_1> \k<match_1> -  instead 
of numbered  (...) \1

(?<match_1>searchstring)[^@\r\n]{0,64}\@[^@\r\n]{0,64}\k<match_1>

When ever possible don not use   .*  - instead look for a less greedy 
variant. .* with the (?is:  switch (assp uses it) will force the regex 
engine to search until the end of the string (mail) and to trace back 
(several thousand times).
There are better (less CPU, less time) solutions for the regex using 
lookahead assertations - but this will go beyond the scope.


There is no need to disable regex-optimization anyway - because there is a 
\r in the regex. The optimizer has a bug, which destroys the \r to \\r - 
so assp disables the optimizer if a regex contains a \r .
How ever, to prevent the regex from failing after possible future assp 
code changes, you may use:

<<<(?:(?<match_1>searchstring)[^@\r\n]{0,64}\@[^@\r\n]{0,64}\k<match_1>)>>>
or

(?<match_1>searchstring)[^@\r\n]{0,64}\@[^@\r\n]{0,64}\k<match_1>.?

the later one seems to be the best of both


normaly you would write

<<<(?<match_1>searchstring)[^@\r\n]{0,64}\@[^@\r\n]{0,64}\k<match_1>>>>

but assp will destroy the trailing four >>>>  (I'm sure)


If more than one string is searched - use:

~<<<(?:(?<match_1>searchstring1|searchstring2|searchstring3)[^@\r\n]{0,64}\@[^@\r\n]{0,64}\k<match_1>)>>>~
or
~<<<(?<match_1>searchstring1|searchstring2|searchstring3)[^@\r\n]{0,64}\@[^@\r\n]{0,64}\k<match_1>.?>>>~


Want to know more about regular expressions?  ->  
http://www.rexegg.com/regex-lookarounds.html


Thomas



Von:    "K Post" <nntp.p...@gmail.com>
An:     "ASSP development mailing list" <assp-test@lists.sourceforge.net>
Datum:  04.11.2021 02:29
Betreff:        [Assp-test] RegEx Backreferences - the basics



I've got nothing in my TestRe file except for a single line:

~<<<(?:^|\n\r).*(searchstring).*@.*\1.*>>>~

The idea is to log any time there's a line that includes "searchstring" on 
the right and left of an @.  This is just a very rudimentary test because 
backreferences seem to error for me.  I would expect this to match
searchstring@searchstring
something else seachstring more @ whatever searchstring bla
If "searchstring" is to the right and left of an @ sign, it should match.  
Regex101.com seems to confirm that this works.  Like I said, super basic.

However, if I enter ~<<<(?:^|\n\r).*(searchstring).*@.*\1.*>>>~ as the 
only line in TestRe file, I get a warning in the log:

- Reference to nonexistent group in regex; marked by <-- HERE in 
m/(?is:(?:^|\n\r).*(?:searchstring).*@.*\1 <-- HERE .*)/ 
- try using unoptimized regex

To my understanding, the <<< >>> surround should turn of regex 
optimization for that line, which enables backreferencing (\1) to work and 
the ~ is required because there's an or in there.   Shouldn't the \1 
reference (searchstring) ?  I don't understand why assp thinks that \1 is 
a reference to a non-existent group.

I also tried removing the <<< >>> and adding assp-do-not-optimize to the 
top of the TestRe file.  No difference.    No matter how simple I make the 
regex, even (.*)@\1,  it still complains about the invalid backreference.
 

I've got to be missing something incredibly obvious.  I've read through 
the regex doc in docs, but that doesn't talk about backreferencing in ASSP 
and I can't find anything in the GUI that makes mention. I've seen posts 
here indicating that backreferencing matches is possible with an 
unoptimized expression.
  
A shove in the right direction would be greatly appreciated.
_______________________________________________
Assp-test mailing list
Assp-test@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/assp-test




DISCLAIMER:
*******************************************************
This email and any files transmitted with it may be confidential, legally 
privileged and protected in law and are intended solely for the use of the 

individual to whom it is addressed.
This email was multiple times scanned for viruses. There should be no 
known virus in this email!
*******************************************************


_______________________________________________
Assp-test mailing list
Assp-test@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/assp-test

Reply via email to