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

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

Closed
zackw opened this issue Oct 8, 2018 · 3 comments
Closed
Labels

Comments

@zackw
Copy link

zackw commented Oct 8, 2018

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.

@BurntSushi
Copy link
Member

Could you please provide a program that reproduces the undesirable behavior? \ is already supported when x mode is enabled. See: https://play.rust-lang.org/?gist=32be08ffca301141e19037e296767725&version=stable&mode=debug&edition=2015

@BurntSushi
Copy link
Member

See also: #501 (comment)

@zackw
Copy link
Author

zackw commented Oct 8, 2018

Could you please provide a program that reproduces the undesirable behavior? \ is already supported when x mode is enabled.

I was just going by the documentation. Please consider this a request to change the documentation so it says r"(?x)When\ in\ the\ course\ of\ human\ events" will indeed behave the same way /When\ in\ the\ course\ of\ human\ events/x would in Perl. (If you want to continue recommending the use of \x20 instead, that's fine by me.)

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

No branches or pull requests

2 participants