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

  • Home
  • SEARCH
  • 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 6345999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:55:56+00:00 2026-05-24T20:55:56+00:00

I am having an issue with regexp in C#. I’ve been using theses patterns

  • 0

I am having an issue with regexp in C#.
I’ve been using theses patterns in F# and it works fine, so i don’t understand why it would’nt work in C#.

So let’s say i’ve got a muline input file. I need to parse this file for specific data:

Exemple:

    Lorem ipsum dolor sit amet, consectetur adipiscing elit (Token1 : 42)
    Aliquam id ante ut ante tempus fringilla Token2 (ante ut ) : 45
    Morbi varius adipiscing lacus, eget pellentesque tellus vulputate Token3 :  43

I basicaly need to retrieve the numbers written after Token1, Token2 , Token3 in a single match ( ie just want my number as a result).
The patterns i used in F# are the following ones:

PatternToken1 = "(?:Token1 : )(\d+)"
PatternToken2 = "(?:Token2.* : )(\d+)"
PatternToken3 = "(?:Token3 : )(\d+)"

So my issue is the following one :
pattern matching my input string in F# would give me the following results:

 MatchedToken1 = 42
 MatchedToken2 = 45
 MatchedToken3 = 43

In C# i would get the following results:

 MatchedToken1 = Token1 : 42
 MatchedToken2 = Token2 (ante ut ) : 45
 MatchedToken3 = Token3 :  43

How come this works in F# and not in C# ? What kind of pattern must i use for it to work in C#?

EDIT:
Here is the code i use to match my patterns in c#:

 abstract class  PatternMatcherBaseEntity<T>
{
    protected Regex Pattern;
    protected T Match;


    private static TK Convert<TK>(string input)
    {
        TK res=default(TK);
        var converter = TypeDescriptor.GetConverter(typeof(TK));
        if(converter != null)
        {
            try
            {
                res = (TK) converter.ConvertFromString(input);
            }
            catch (Exception)
            {
                res = default(TK);
            }

        }
        return res;
    }


    protected bool Matcher(string s)
    {
        var res = false;
        //var matchedData = Regex.Match(s, Patterm);
        var content = Pattern.Matches(s);
        if(content.Count>0)
        {
            //Match = Convert<T>(content.Value);
            Match = Convert<T>(content[0].Value);
            res = true;
        }
        return res;
    }

    public T MatchGetter(String stringToMatch)
    {
        T ret = default(T);
        if(stringToMatch != String.Empty)
        {
            ret = stringToMatch.Match()
            .With(Matcher, x => Match)
            .Else(x => default(T))
            .Do();
        }
        return ret;
    }
}

by the way i’ve tested using verbatim strings and escape string. It would not compile otherwise

  • 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-24T20:56:00+00:00Added an answer on May 24, 2026 at 8:56 pm

    Try using the following:

    PatternToken1 = "(?<=Token1 : )(\d+)"
    PatternToken2 = "(?<=Token2.* : )(\d+)"
    PatternToken3 = "(?<=Token3 : )(\d+)"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having an issue in php... I don't fully understand how the whole
I'm having an issue with CruiseControl.net where the web dashboard just won't work in
I having an issue from my HTTP Post. The code I'm using are working
I'm having a annoying issue with rewrite-using cherokee web-server. I want to convert: http://example.com/mypage.phtml?cmd=print
I think I'm having an issue since I'm using two key regex values in
I'm having a little issue with getting a value of field in HTML using
I'm having an issue with a function I'm calling (using jQuery). My issue is
I'm having an issue with my regex. I want to capture <% some stuff
I'm having an issue with a query that currently uses LEFT JOIN weblog_data AS
I'm having an issue with a Flash/Flex erroring in Firefox but not IE. I

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.