-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
  • 38,279
  • 56
  • 171
  • 280
DaveG
  • 441
  • 1
  • 6
  • 17

2 Answers2

3

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

Output c#

The fourth bird
  • 127,136
  • 16
  • 45
  • 63
0

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

Sample Code

蔡宇祥
  • 36
  • 1
  • 3