Skip to content

Document RegexOptions.AnyNewLine#52328

Open
danmoseley wants to merge 8 commits intodotnet:mainfrom
danmoseley:anynewline-docs
Open

Document RegexOptions.AnyNewLine#52328
danmoseley wants to merge 8 commits intodotnet:mainfrom
danmoseley:anynewline-docs

Conversation

@danmoseley
Copy link
Member

@danmoseley danmoseley commented Mar 17, 2026

Document the new RegexOptions.AnyNewLine option in conceptual docs, shipping in .NET 11 Preview 3.

Changes

regular-expression-options.md

  • New AnyNewLine mode section with explanation, before/after code examples, behavior table, and design notes
  • Added a [!TIP] in the Multiline mode section pointing to AnyNewLine as an alternative to the \r?$ workaround

anchors-in-regular-expressions.md

  • Added note in End of String or Line: $ section about AnyNewLine as an alternative to \r?$
  • Added note in End of String or Before Ending Newline: \Z section about AnyNewLine as an alternative to \r?\Z

character-classes-in-regular-expressions.md

  • Added bullet in Any character: . section explaining AnyNewLine effect on .

Context

AnyNewLine makes ^, $, \Z, and . recognize all Unicode newline sequences (\r\n, \r, \n, \u0085, \u2028, \u2029) instead of only \n. This addresses one of the most common regex pitfalls in .NET -- that $ doesn't match before \r\n and . matches \r.

Related:


Internal previews

📄 File 🔗 Preview link
docs/standard/base-types/anchors-in-regular-expressions.md Anchors in Regular Expressions
docs/standard/base-types/character-classes-in-regular-expressions.md Character Classes in .NET Regular Expressions
docs/standard/base-types/regular-expression-options.md Regular expression options

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the .NET regular expressions documentation to introduce and explain the new RegexOptions.AnyNewLine option (starting in .NET 11), including how it affects anchors and the . wildcard across common newline sequences.

Changes:

  • Adds RegexOptions.AnyNewLine to the options reference table and the “options that can’t be set inline” list.
  • Introduces a new “AnyNewLine mode” section with behavioral details and examples.
  • Cross-links related docs (anchors and character classes) to describe how $, \Z, and . behave under AnyNewLine.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
docs/standard/base-types/regular-expression-options.md Documents RegexOptions.AnyNewLine, adds a new dedicated section, and updates option lists.
docs/standard/base-types/character-classes-in-regular-expressions.md Notes how . changes under AnyNewLine and links back to the new mode section.
docs/standard/base-types/anchors-in-regular-expressions.md Adds guidance for $ and \Z when using AnyNewLine instead of \r? workarounds.

Add AnyNewLine mode section to Regular Expression Options article.
Add tips/notes about AnyNewLine in:
- Multiline mode section (as alternative to \r?\$ workaround)
- Anchors doc (\$ and \Z sections)
- Character classes doc (Any character: . section)
- Quick reference (options table)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@danmoseley danmoseley requested a review from Copilot March 17, 2026 04:45
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds documentation for the new RegexOptions.AnyNewLine behavior across the core regex conceptual articles, explaining how it changes newline handling for anchors and the . wildcard.

Changes:

  • Documents RegexOptions.AnyNewLine in the options reference table and option-setting guidance.
  • Adds a dedicated “AnyNewLine mode” section with examples and a behavior summary table.
  • Updates anchor and character class docs to reference AnyNewLine and link to the new section.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
docs/standard/base-types/regular-expression-options.md Adds AnyNewLine to the options list, introduces a new section describing its semantics, and adds examples/table.
docs/standard/base-types/character-classes-in-regular-expressions.md Notes how AnyNewLine changes . behavior and precedence with Singleline.
docs/standard/base-types/anchors-in-regular-expressions.md Notes how AnyNewLine changes $ and \Z behavior vs \r? workarounds.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@danmoseley
Copy link
Member Author

red because links need merge of dotnet/dotnet-api-docs#12405

@danmoseley
Copy link
Member Author

@copilot fix feedback

danmoseley and others added 4 commits March 19, 2026 16:01
Apply gewarren's suggestion to align table columns for readability.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Clarifies that the . behavior described applies without Singleline,
consistent with how other rows qualify their mode.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@adegeo adegeo modified the milestones: March 2026, April 2026 Mar 20, 2026
@gewarren gewarren added the 🚧 Hold for related PR Indicates a PR can only be merged when other related PRs are merged (see comments for links) label Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🚧 Hold for related PR Indicates a PR can only be merged when other related PRs are merged (see comments for links) dotnet-fundamentals/svc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants