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 3426950
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:46:38+00:00 2026-05-18T06:46:38+00:00

I have any text in C#, and I need match using Regular Expressions, and

  • 0

I have any text in C#, and I need “match” using Regular Expressions, and get a value (parsing the text for get the value).

Texts:

var asunto1 = “ID P20101125_0003 —
Pendiente de autorización –“;

var asunto2 = “ID P20101125_0003 any
text any text”;

var asunto3 = “ID_P20101125_0003 any
text any text”;

I need get the value:

var peticion = “P20101125_0003”;

I have this regular expression, but fails for me:

    //ID P20101125_0003 -- Pendiente de autorización --

            patternPeticionEV.Append(@"^");
            patternPeticionEV.Append(@"ID P");
            patternPeticionEV.Append(@"(20[0-9][0-9])"); // yyyy
            patternPeticionEV.Append(@"(0[1-9]|1[012])"); // MM
            patternPeticionEV.Append(@"(0[1-9]|[12][0-9]|3[01])"); // dd
            patternPeticionEV.Append(@"(_)"); 
            patternPeticionEV.Append(@"\d{4}");
            //patternPeticionEV.Append(@"*");
            patternPeticionEV.Append(@"$");

if (System.Text.RegularExpressions.Regex.IsMatch(asuntoPeticionEV, exprRegular, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
            {
                var match = System.Text.RegularExpressions.Regex.Match(asuntoPeticionEV, exprRegular, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
//...
            }
  • 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-18T06:46:39+00:00Added an answer on May 18, 2026 at 6:46 am

    Your regular expression ends with “$” which says “the line/text has to end there”. You don’t want that. Just get rid of this line:

    patternPeticionEV.Append(@"$");
    

    and it will mostly work immediately. You then just need to add a capturing group to isolate the bit of text that you want.

    I’d also recommend adding using System.Text.RegularExpressions; so that you don’t have to fully qualify Regex each time. You can also call Match and then check for success, to avoid matching it twice.

    Sample code:

    using System.Text.RegularExpressions;
    
    class Test
    {
        static void Main()
        {
            DisplayMatch("ID P20101125_0003 -- Pendiente de autorización --");
            // No match due to _
            DisplayMatch("ID_P20101125_0003 any text any text");
        }
    
        static readonly Regex Pattern = new Regex
            ("^" + // Start of string
             "ID " +
             "(" + // Start of capturing group
             "P" +
             "(20[0-9][0-9])" + // yyyy
             "(0[1-9]|1[012])" + // MM
             "(0[1-9]|[12][0-9]|3[01])" + // dd
             @"_\d{4}" +
             ")" // End of capturing group
             );
    
        static void DisplayMatch(string input)
        {
            Match match = Pattern.Match(input);
            if (match.Success)
            {
                Console.WriteLine("Matched: {0}", match.Groups[1]);
            }
            else
            {
                Console.WriteLine("No match");
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.