How can I convert a string to a string literal for regex
I want to do some regex.match by building the pattern dynamically. The following code is not working due to string literial issue. I was wandering how can I get it to work.

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 = "UA";
            Regex re = new Regex(Convert("^NN$"));
            if (re.Match(seq).Success)
            {
                Console.WriteLine("match");
            }



            Console.ReadKey();
        }
How can I convert a string to a string literal for regex
===

I want to do some regex.match by building the pattern dynamically. The following code is not working due to string literial issue. I was wandering how can I get it to work.

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 = "UA";
            Regex re = new Regex(Convert("^NN$"));
            if (re.Match(seq).Success)
            {
                Console.WriteLine("match");
            }



            Console.ReadKey();
        }