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

Conversation

ksami
Copy link

@ksami ksami commented Oct 18, 2018

No description provided.

@PRMerger9
Copy link
Contributor

@ksami : Thanks for your contribution! The author, @gewarren, has been notified to review your proposed change.

|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

@gewarren gewarren closed this Oct 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants