ErythroGuild / irene

<Erythro>'s server admin bot.
Mozilla Public License 2.0
0 stars 0 forks source link

Investigate using non-backtracking option for regex #389

Open Ernest314 opened 1 year ago

Ernest314 commented 1 year ago

This requires .NET 7. This would guarantee regex search times be linear, and most regexes should still work fine.

Ernest314 commented 1 year ago

regex101.com doesn't have support for this yet, but it seems there might be interest?

Ernest314 commented 1 year ago

See: https://learn.microsoft.com/en-us/dotnet/standard/base-types/backtracking-in-regular-expressions

Ernest314 commented 1 year ago

Lots more detail on how the option works here: https://devblogs.microsoft.com/dotnet/regular-expression-improvements-in-dotnet-7/#backtracking-and-regexoptions-nonbacktracking

Note: this engine constructs a DFA instead of an NFA, and has a bounded worst-case runtime, but the typical performance may actually be substantially worse than a regular (backtracking) engine. The article has more details and stats.