Skip to content

Python regular expression counts inner groups differently #28

@konard

Description

@konard
// 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions