andgineer / TRegExpr

Regular expressions (regex), pascal.
https://regex.sorokin.engineer/en/latest/
MIT License
174 stars 63 forks source link

zero-length match not found at the end of searched string #265

Closed white-gthb closed 2 years ago

white-gthb commented 2 years ago

Unlike in earlier versions, TRegExpr in certain cases no longer matches an zero-length match at the end of a string. Apparently some optimization was done to TRegExpr constituting to new behavior which I consider to be a bug.

Examples of effected regular expressions:

(?:)
(_[a-zA-Z]+_)?
.*\b
Q{0,5}

How this works out and where I first reported this can be read here: https://www.ghisler.ch/board/viewtopic.php?t=76139

In any case, this new behavior is not consistent with older versions of TRegExpr and seemingly all other regular expression engines.

white-gthb commented 2 years ago

Subject string basically can be any string. The position found by earlier versions of TRegExp and other engines is at the end of the string. Some examples are given in the mentioned thread on the official forum of Total Commander.

Alexey-T commented 2 years ago

I tried 2 first examples from TC forum

1.

Filename:       12345

Search for:     (?:)
Replace with:       -
1x:         Disabled
Subst:          Disabled

Result:         -1-2-3-4-5
Expected result:    -1-2-3-4-5-

executed replace in CudaText (it uses this engine). result is OK!

Screenshot from 2022-04-25 15-08-51

2.

Filename:       1234_text_ABCD

Search for:     (_[a-zA-Z]+_)?
Replace with:       __
1x:         Disabled
Subst:          Disabled

Result:         __1__2__3__4____A__B__C__D
Expected result:    __1__2__3__4____A__B__C__D__

executed in CudaText. OK again! Screenshot from 2022-04-25 15-08-26

Alexey-T commented 2 years ago

make sure that TCmd uses the LAST version of TRegexpr.

white-gthb commented 2 years ago

Thanks for testing! I will notify the author.

white-gthb commented 2 years ago

Author says latest trunk code seems to work.

Alexey-T commented 2 years ago

so you can close this issue.

Alexey-T commented 2 years ago

@andgineer Author of TotalCommander said that 'regexpr last release is from 2017' so he took that old code. Can you make the Github release?

andgineer commented 2 years ago

Ok I am not sure what for but I created the release https://github.com/andgineer/TRegExpr/releases/tag/1.155

Alexey-T commented 2 years ago

Thanks