Skip to content

Support \ (backslash space) as equivalent to space, at least in /x mode #523

@zackw

Description

@zackw

The documentation for insignificant-whitespace mode says this:

If you wish to match against whitespace in this mode, you can still use \s, \n, \t, etc. For escaping a single space character, you can use its hex character code \x20 or temporarily disable the x flag, e.g., (?-x: ).

Most other regex engines that support /x mode (and in particular Perl, which invented it) accept \ (backslash space) as equivalent to space and treat it as significant within /x mode. This can be significantly more readable than either of the alternatives supported by Rust, compare

Regex.new(r"(?x)When\ in\ the\ course\ of\ human\ events")

Regex.new(r"(?x)When\x20in\x20the\x20course\x20of\x20human\x20events")

And it would also ease porting code from other languages if Rust supported this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions