Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 674603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:43:31+00:00 2026-05-14T00:43:31+00:00

I am trying to find every a -> b, c, d pattern in an

  • 0

I am trying to find every “a -> b, c, d” pattern in an input string.
The pattern I am using is the following :

"^[ \t]*(\\w+)[ \t]*->[ \t]*(\\w+)((?:,[ \t]*\\w+)*)$"

This pattern is a C# pattern, the “\t” refers to a tabulation (its a single escaped litteral, intepreted by the .NET String API), the “\w” refers to the well know regex litteral predefined class, double escaped to be interpreted as a “\w” by the .NET STring API, and then as a “WORD CLASS” by the .NET Regex API.

The input is :

a -> b
b -> c
c -> d

The function is :

private void ParseAndBuildGraph(String input) {
    MatchCollection mc = Regex.Matches(input, "^[ \t]*(\\w+)[ \t]*->[ \t]*(\\w+)((?:,[ \t]*\\w+)*)$", RegexOptions.Multiline);
    foreach (Match m in mc) {
        Debug.WriteLine(m.Value);
    }
}

The output is :

c -> d

Actually, there is a problem with the line ending “$” special char. If I insert a “\r” before “$”, it works, but I thought “$” would match any line termination (with the Multiline option), especially a \r\n in a Windows environment. Is it not the case ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:43:32+00:00Added an answer on May 14, 2026 at 12:43 am

    This surprised me, too. In .NET regexes, $ doesn’t match before a line separator, it matches before a linefeed–the character \n. This behavior is consistent with Perl’s regex flavor, but it’s still wrong, in my opinion. According to the Unicode standard, $ should match before any of:

    \n, \r\n, \r, \x85, \u2028, \u2029, \v or \f

    …and never match between \r and \n. Java complies with that (except \v and \f), but .NET, which came out long after Java, and whose Unicode support is at least as good as Java’s, only recognizes \n. You’d think they would at least handle \r\n correctly, given how strongly Microsoft is associated with that line separator.

    Be aware that . follows the same pattern: it doesn’t match \n (unless Singleline mode is set), but it does match \r. If you had used .+ instead of \w+ in your regex, you might not have noticed this problem; the carriage-return would have been included in the match, but the console would have ignored it when you printed the results.

    EDIT: If you want to allow for the carriage return without including it in your results, you can replace the anchor with a lookahead: (?=\r?\n.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to find a best practice to load usercontrols using Ajax. My first
I am trying to find a good pattern to use for user access validation.
Hello I been trying to find this memory leak for a while now and
I've spent about 10 hours trying to find this bug that was causing my
I am trying to find out the frequency of appearance of every letter in
I am trying to find the @ in a string field. The follow data
I have been trying to find answers to this question, and I'm currently baffled.
Hey again guys. So, I'm trying to find out how to select every field
I'm trying to find certain keywords in a string with python. The string is
I'm trying to write a method that does the following: Replace every occurrence of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.