-1

Here's my code:

using System;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
namespace ConsoleApplication33
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = "\"aaaaa\"" + "aaaaa" + "\"aaaaa\"" + "aaaaa" + "\"aaaaa\"";
            line = Regex.Replace(line, "\".+\"", "");
            Console.WriteLine(line);
            Console.Read();
        }
    }
}

I want get rid of "aaaaa" and keepaaaaa.

So with this string I should get aaaaaaaaaa.

But with the code I get nothing.

So how can I fix this?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
DaveG
  • 491
  • 1
  • 6
  • 19

2 Answers2

3

I think you should make the .+ non greedy .+?

Output c#

The fourth bird
  • 154,723
  • 16
  • 55
  • 70
0

I also try it, you should replace .+ to .+?

Sample Code

蔡宇祥
  • 36
  • 1
  • 3