Skip to content

Clarify CRLF mode effect #1165

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

Merged
merged 1 commit into from
Aug 24, 2025
Merged

Clarify CRLF mode effect #1165

merged 1 commit into from
Aug 24, 2025

Conversation

CAD97
Copy link
Contributor

@CAD97 CAD97 commented Feb 14, 2024

In multi-line CRLF mode (?Rm), the start-of-line and end-of-line assertions match either \r or \n; the current documentation says "and" instead. The use of "and" implies that the full two-byte \r\n sequence is required, but that's not the case; a lone \n still satisfies the assertions, as does a lone \r. "or" makes this clear, and was likely intended; "either $x and $y" doesn't make grammatical sense. You could argue for using "and/or" to emphasize that the assertions do match \r\n newlines, but I think doing so is probably unnecessary and what the "and" could be trying to communicate is much better said by the immediately following clause anyway.

Tested:

[src/main.rs:5:5] Regex::new(r"(?Rm)^$")?.find_iter("\r\r\n\n").count() = 4

Copy link
Member

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, "or" was definitely intended. Thank you. :-)

Could you apply the same fix to regex-lite/src/lib.rs? It looks like it has precisely the same mistake. (Many of its docs are copy & pasted from regex proper.)

@BurntSushi
Copy link
Member

I applied the requested doc fix to regex-lite.

@BurntSushi BurntSushi merged commit dd96592 into rust-lang:master Aug 24, 2025
13 checks passed
@CAD97 CAD97 deleted the patch-2 branch August 24, 2025 18:16
@CAD97
Copy link
Contributor Author

CAD97 commented Aug 24, 2025

Oop, sorry, completely missed the follow up request. Glad this got merged eventually.

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

Successfully merging this pull request may close these issues.

2 participants