') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Document RegexOptions.AnyNewLine by danmoseley · Pull Request #52328 · dotnet/docs · GitHub
Skip to content

Document RegexOptions.AnyNewLine - #52328

Merged
gewarren merged 10 commits into
dotnet:mainfrom
danmoseley:anynewline-docs
Apr 15, 2026
Merged

Document RegexOptions.AnyNewLine#52328
gewarren merged 10 commits into
dotnet:mainfrom
danmoseley:anynewline-docs

Conversation

@danmoseley

@danmoseleydanmoseley commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

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.mdAnchors in Regular Expressions
docs/standard/base-types/character-classes-in-regular-expressions.mdCharacter Classes in .NET Regular Expressions
docs/standard/base-types/regular-expression-options.mdRegular expression options

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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.

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

Comment threaddocs/standard/base-types/character-classes-in-regular-expressions.md Outdated
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 CopilotMarch 17, 2026 04:45
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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.

FileDescription
docs/standard/base-types/regular-expression-options.mdAdds 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.mdNotes how AnyNewLine changes . behavior and precedence with Singleline.
docs/standard/base-types/anchors-in-regular-expressions.mdNotes how AnyNewLine changes $ and \Z behavior vs \r? workarounds.

Comment threaddocs/standard/base-types/regular-expression-options.md
Comment threaddocs/standard/base-types/regular-expression-options.md
Comment threaddocs/standard/base-types/anchors-in-regular-expressions.md
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@danmoseley

Copy link
Copy Markdown
ContributorAuthor

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

Comment threaddocs/standard/base-types/regular-expression-options.md Outdated
@danmoseley

Copy link
Copy Markdown
ContributorAuthor

@copilot fix feedback

Dan Moseleyand 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>
@adegeoadegeo modified the milestones: March 2026, April 2026Mar 20, 2026
@gewarrengewarren 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
@danmoseley

Copy link
Copy Markdown
ContributorAuthor

@copilot resolve the merge conflicts in this pull request

@danmoseley

Copy link
Copy Markdown
ContributorAuthor

@gewarren this shipped in preview 3. can we merge? I'll try re-running the build to see whether link warnigns are gone.

@danmoseleydanmoseley reopened this Apr 14, 2026
@danmoseley

Copy link
Copy Markdown
ContributorAuthor

Although, I don't see it in the APi docs yet (or not indexed anyway):
https://learn.microsoft.com/en-us/search/?terms=anynewline

@gewarren

Copy link
Copy Markdown
Collaborator

@gewarren this shipped in preview 3. can we merge? I'll try re-running the build to see whether link warnigns are gone.

The CI to update the API ref docs is still running. I'll be sure to merge this PR once that is published.

Comment threaddocs/standard/base-types/anchors-in-regular-expressions.md Outdated
Comment threaddocs/standard/base-types/anchors-in-regular-expressions.md Outdated
@gewarren
gewarren enabled auto-merge (squash) April 15, 2026 17:29
auto-merge was automatically disabled April 15, 2026 17:52

Pull request was closed

@gewarrengewarren reopened this Apr 15, 2026
@gewarren
gewarren enabled auto-merge (squash) April 15, 2026 17:53
@gewarren
gewarren merged commit a6742c2 into dotnet:mainApr 15, 2026
15 of 16 checks passed
@danmoseley
danmoseley deleted the anynewline-docs branch April 15, 2026 18:50
@danmoseley

Copy link
Copy Markdown
ContributorAuthor

@gewarren on https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-options right now I see the literal <xref:System.Text.RegularExpressions.RegexOptions.AnyNewLine>

I assume this is latency thing that will heal itself

@danmoseley

Copy link
Copy Markdown
ContributorAuthor

It has healed itself!

@danmoseley

Copy link
Copy Markdown
ContributorAuthor

@gewarren

Copy link
Copy Markdown
Collaborator

But in the APi docs side -- this has a blank description for ANL: https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regexoptions?view=net-11.0#system-text-regularexpressions-regexoptions-anynewline

@danmoseley The docs will need to be ported separately since the /// isn't the source of truth for this library.

@danmoseley

Copy link
Copy Markdown
ContributorAuthor

Is there a guide for making a library source of truth? Maybe I could do this one

@gewarren

Copy link
Copy Markdown
Collaborator

Is there a guide for making a library source of truth? Maybe I could do this one

@danmoseley That would be great. There is a guide of sorts here: dotnet/dotnet-api-docs#10722.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🚧 Hold for related PRIndicates 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

@danmoseley@gewarren@adegeo