Skip to content

Fix RegexOptions.IgnorePatternWhitespace # to EOL #24936

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 2 commits into from
Jul 6, 2021

Conversation

kevinoid
Copy link
Contributor

The Regular Expression Options documentation currently states that

All text in the regular expression pattern from the # character to the end of the string is interpreted as a comment.

when RegexOptions.IgnorePatternWhitespace is in effect. This omits the fact that # behaves as a line comment when the pattern contains multiple lines. It causes the text from # to the end of the line, denoted by \n, to be interpreted as a comment. For example:

using System.Text.RegularExpressions;

Console.WriteLine(Regex.Match(
    "Hello World",
    "Hello # Line Comment\n\\sWorld",
    RegexOptions.IgnorePatternWhitespace));

Prints "Hello World", rather than "Hello" as it does if \n is removed or replaced by \r.

This PR adds this behavior to the documentation.

Thanks for considering,
Kevin


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

The documentation currently states that

> All text in the regular expression pattern from the # character to the
> end of the string is interpreted as a comment.

when `RegexOptions.IgnorePatternWhitespace` is in effect.  This omits
the fact that `#` behaves as a line comment when the pattern contains
multiple lines.  It causes the text from `#` to the end of the line,
denoted by `\n`, to be interpreted as a comment.  For example:

```csharp
using System.Text.RegularExpressions;

Console.WriteLine(Regex.Match(
    "Hello World",
    "Hello # Line Comment\n\\sWorld",
    RegexOptions.IgnorePatternWhitespace));
```

Prints "Hello World", rather than "Hello" as it does if `\n` is removed
or replaced by `\r`.

This commit adds this behavior to the documentation.

Signed-off-by: Kevin Locke <[email protected]>
@kevinoid kevinoid requested a review from adegeo as a code owner June 30, 2021 23:51
@dotnet-bot dotnet-bot added this to the July 2021 milestone Jun 30, 2021
@adegeo adegeo added the ✨ 1st-time docs contributor! Indicates PRs from new contributors to the docs repository label Jul 6, 2021
Copy link
Contributor

@adegeo adegeo left a comment

Choose a reason for hiding this comment

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

Thanks a bunch for spotting that inaccuracy!

@adegeo adegeo merged commit 0063cc2 into dotnet:main Jul 6, 2021
@kevinoid
Copy link
Contributor Author

kevinoid commented Jul 7, 2021

My pleasure. Thanks for reviewing and merging @adegeo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet-fundamentals/svc ✨ 1st-time docs contributor! Indicates PRs from new contributors to the docs repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants