linksplatform / RegularExpressions.Transformer.CSharpToCpp

LinksPlatform's Platform.RegularExpressions.Transformer.CSharpToCpp Class Library
https://linksplatform.github.io/RegularExpressions.Transformer.CSharpToCpp
The Unlicense
10 stars 1 forks source link

Python regular expression counts inner groups differently #28

Open Konard opened 4 years ago

Konard commented 4 years ago
// class Program { }
// class Program { };
(new Regex(@"(struct|class) ([a-zA-Z0-9]+[^\r\n]*)([\r\n]+(?<indentLevel>[\t ]*)?)\{([\S\s]+?[\r\n]+\k<indentLevel>)\}([^;]|$)"), "$1 $2$3{$4};$5", Null, 0),
# class Program { }
# class Program { };
(r"(struct|class) ([a-zA-Z0-9]+[^\r\n]*)([\r\n]+(?P<indentLevel>[\t ]*)?)\{([\S\s]+?[\r\n]+(?P=indentLevel))\}([^;]|$)", r"\1 \2\3{\5};\6", None, 0),

Compare: "$1 $2$3{$4};$5" and r"\1 \2\3{\5};\6".

To be able to write expression that can be easily translated from C# to Python we should use group names not numbers.

Konard commented 4 years ago

This fact should be added to documentation. The issue should be open until that time.