Search accepts invalid regexes

Report issues, odd behaviors or submit a detailed bug report.
Post Reply
User avatar
pjj
Posts: 1942
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Search accepts invalid regexes

Post by pjj »

Is it a bug? Is it a feature? After some deliberation I decided it's the former.

I tried to replace all occurrences of string

Code: Select all

|yes
at the end of the line with

Code: Select all

|1
, so I used

Code: Select all

|yes$
as my "find" string, checked "regular expressions" box, hit "replace all" and my editor hung. Then I did some experiments with various regexes and concluded that there's a serious bug in RJ TE's regex engine. Only when I checked my approach at RegExr excellent regex tester, I realized there's no bug in the editor, at least not the one I thought there was. Simply put, character I used (I = pipe) has special meaning in regular expressions... RegExr gives you this warning:
The expression can return empty matches, and may match infinitely in some use cases.
I guess this was my case... It would be cool if RJ TE could give such warnings, too!

Where's the bug? The bug is accepting invalid regexes (in such cases RegExr warns you about an error, not gives a warning). Some examples:

Code: Select all

*
[
[0-9]++
BOOM\
source

If I use any of the above, RJ TE gives me "0 results", which is technically true, but misses the point, cf. this conversation on similar fault in NPP:
I expect to be told that my regular expression is not correct, and other search activities to be aborted. Zero matches is misleading when the true problem is that a search parameter is incorrect.
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus

User avatar
Rickard Johansson
Site Admin
Posts: 6191
Joined: 19 Jul 2006 14:29

Re: Search accepts invalid regexes

Post by Rickard Johansson »

[Find or Replace] should give a give an error message.

Code: Select all

Ex. 
Find: abc[def
Error message: Error in regular expression at offset 7: missing terminating ] for character class
I suppressed all error messages in all other operations because they are executed in a thread.

I've fixed it in the next release (v15.30). An error message is displayed if an error is found (with all search operations).

It wont help in your example though. The regEx engine only reports actual errors. It doesn't offer any validation of the expression or display any warnings before execution.

User avatar
pjj
Posts: 1942
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Re: Search accepts invalid regexes

Post by pjj »

Rickard Johansson wrote:
09 Dec 2021 15:45
It wont help in your example though. The regEx engine only reports actual errors. It doesn't offer any validation of the expression or display any warnings before execution.
I know. I tried to find a list of such invalid regexes -- some are called evil, but failed. Perhaps this could be tackled in another way, then: if replacing takes too long (because counting is instant), break it with a message (there is "abort" button, but it doesn't work if regex engine is in a loop).
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus

User avatar
Rickard Johansson
Site Admin
Posts: 6191
Joined: 19 Jul 2006 14:29

Re: Search accepts invalid regexes

Post by Rickard Johansson »

The abort button should work now in the next release (v15.30) :)

Post Reply