Skip to content

fix regex for end of line #1707

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/ide/using-regular-expressions-in-visual-studio.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ Here are some examples:
|Match any character one or more times (Wildcard ?)|.+|`e.+e` matches "eede" in "feeder" but not "ee".|
|Match zero or more occurrences of the preceding expression (match as few characters as possible)|*?|`e.*?e` matches "ee" in "feeder" but not "eede".|
|Match one or more occurrences of the preceding expression (match as few characters as possible)|+?|`e.+?e` matches "ente" and "erprise" in "enterprise", but not the whole word "enterprise".|
|Anchor the match string to the beginning of a line or string|^|`^car` matches the word "car" only when it appears at the beginning of a line.|
|Anchor the match string to the end of a line|\r?$|`End\r?$` matches "end" only when it appears at the end of a line.|
|Anchor the match string to the beginning of a line|^|`^car` matches the word "car" only when it appears at the beginning of a line.|
|Anchor the match string to the end of a line|$|`end$` matches the word "end" only when it appears at the end of a line.|
Copy link
Member

Choose a reason for hiding this comment

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

@ksami This is not the behavior I'm seeing in Visual Studio. Is this perhaps for a different flavor of regular expressions? The \r?$ is what matches the end of a line in Visual Studio.

Copy link
Author

Choose a reason for hiding this comment

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

Nope, I'm going by this https://docs.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference#anchors. \r?$ does work, the \r? seemed unnecessary for me but I now realise I'm using Visual Studio for Mac.

I have to note though that anchoring to the end of the line actually anchors to the end of the file. Could the description or regex be changed to either make this clearer or anchor to each end of line instead?

Copy link
Member

Choose a reason for hiding this comment

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

@ksami I tried it out and you're right, $ matches the end of the file. I can add a row to the table for that.

To match the end of a line in Visual Studio (on the Windows version at least), one does need the full \r?$ syntax:

image

|Match any single character in a set|[abc]|`b[abc]` matches "ba", "bb", and "bc".|
|Match any character in a range of characters|[a-f]|`be[n-t]` matches "bet" in "between", "ben" in "beneath", and "bes" in "beside", but not "below".|
|Capture and implicitly number the expression contained within parenthesis|()|`([a-z])X\1` matches "aXa"and "bXb", but not "aXb". "\1" refers to the first expression group "[a-z]".|
Expand All @@ -69,4 +69,4 @@ Here are some examples:

## See also

- [Find and replace text](../ide/finding-and-replacing-text.md)
- [Find and replace text](../ide/finding-and-replacing-text.md)