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

Clarify CRLF mode effect #1165

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Clarify CRLF mode effect #1165

wants to merge 1 commit into from

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.)

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.

None yet

2 participants