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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:03:09+00:00 2026-05-28T15:03:09+00:00

I want to do some regex.match by building the pattern dynamically. The following code

  • 0

I want to do some regex.match by building the pattern dynamically. The following code is not working. I was wondering how can I convert the string “^[ABCDEFG][ABCDEFG]$” to @”^[ABCDEFG][ABCDEFG]$” and use it for regex.

Thanks

static string Convert(string s)
    {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i].Equals('N'))
            {
                sb.Append("[ABCDEFG]");
            }
            else
            {
                sb.Append(s[i]);
            }
        }
        return sb.ToString();
    }



    static void Main(string[] args)
    {
        string seq = "CA";
        Regex re = new Regex(Convert("^NN$"));
        if (re.Match(seq).Success)
        {
            Console.WriteLine("match");
        }



        Console.ReadKey();
    }
  • 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-28T15:03:10+00:00Added an answer on May 28, 2026 at 3:03 pm

    A verbatim string (string literal prefixed with a @) is only sytactic sugar to allow simpler file system access and regular expression writing, because in verbatim strings the character \ isn’t treated as an escape character. That way you don’t have to write "\\\\\\.\\\\" to match the string "\.\" in a regex but only @"\\\.\\" which is less prone to error because counting the backslashes becomes easier as their number decreases.

    The following example will prove that verbatim strings are no different from normal ones:

    public class Program
    {
        public string GetString(bool verbatim)
        {
            if(verbatim)
            {
                return @"this is a test";
            }
            else
            {
                return "this is a test";
            }
        }
    
        public static void Main(string[] args)
        {
            var verbatim = GetString(true);
            var normal = GetString(false);
    
            // should print 'true', if I'm not mistaken, because of string interning
            Console.WriteLine("Reference equals:" + ReferenceEquals(verbatim, normal));
    
            // will definitely print 'true'
            Console.WriteLine("Equals:" + verbatim.Equals(normal));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

am having problems with some Regex code can anyone help. I have the following
I want to build a regex that will match the following strings: A string
I'm trying to exclude some data from a string using regex. var match =
I'm parsing some html using regex and I want to match lines which start
I can't get my regex to match the header of a c# code file.
Hi I'm wanting a Regex pattern to match a very specific string syntax. Below
I want to return output match if the pattern regular is a sub-string of
I want to match every single number in the following string: -0.237522264173E+01 0.110011117918E+01 0.563118085683E-01
I want a regex for below strings. string: Some () Text (1) I want
I'm having an issue with my regex. I want to capture <% some stuff

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.