Skip to content

Conversation

@prozolic
Copy link
Contributor

Add support for escaping vertical tab character (\v) in Regex.Escape.
Regex.Unescape already supported \v, but Regex.Escape was missing this functionality.

  • Handle \v character (0x0B) in RegexParser.EscapeImpl
  • Use \v instead of \u000B in RegexParser.ScanCharEscape
  • Add test for vertical tab character in Regex.Escape/Unescape

Related to PR #120625

Copilot AI review requested due to automatic review settings January 12, 2026 02:30
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jan 12, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions
See info in area-owners.md if you want to be subscribed.

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 pull request adds support for escaping the vertical tab character (\v) in Regex.Escape, completing the functionality that was already present in Regex.Unescape. This change builds on PR #120625, which added vertical tab support to the regex parser for IgnorePatternWhitespace.

Changes:

  • Added vertical tab (\v) handling in RegexParser.EscapeImpl to escape the character as \v
  • Changed ScanCharEscape to use \v literal instead of \u000B for consistency
  • Updated comment to document \v as part of whitespace characters
  • Added comprehensive tests for both Escape and Unescape with vertical tab

Reviewed changes

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

File Description
Regex.EscapeUnescape.Tests.cs Added new test methods Escape_VerticalTab and Unescape_VerticalTab to verify vertical tab escaping/unescaping behavior
RegexParser.cs Added case for \v in EscapeImpl, changed \u000B to \v in ScanCharEscape, and updated whitespace comment

@stephentoub
Copy link
Member

Regex.Unescape already supported \v, but Regex.Escape was missing this functionality.

There are many more characters Unescape recognizes that Escape doesn't. Why is this one in particular important to add to Escape?

@prozolic
Copy link
Contributor Author

prozolic commented Jan 12, 2026

In #120625, \v was made to be treated as whitespace like other escape sequences (\t\n\f\r).
During that process, \v was added to s_metachars, which changed the behavior of Regex.Escape when \v is included, so I thought the same handling as \t\n\f\r was necessary.

https://github.com/dotnet/runtime/blob/main/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexParser.cs#L1941-L1942

The mention of Regex.Unescape may have been unnecessary, sorry about that.

@stephentoub
Copy link
Member

It was unintended for Regex.Escape to be impacted by that PR. I'll fix it. Thanks.

@prozolic prozolic deleted the Regex_Escape branch January 12, 2026 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Text.RegularExpressions community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants