Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python regular expression counts inner groups differently #28

Open
Konard opened this issue Mar 26, 2020 · 1 comment
Open

Python regular expression counts inner groups differently #28

Konard opened this issue Mar 26, 2020 · 1 comment

Comments

@Konard
Copy link
Member

Konard commented Mar 26, 2020

// 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 Konard changed the title Python regular expression count groups differently Python regular expression counts groups differently Mar 26, 2020
@Konard Konard changed the title Python regular expression counts groups differently Python regular expression counts inner groups differently Mar 27, 2020
@Konard
Copy link
Member Author

Konard commented Mar 27, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant