0

I'm using c# RegEx to search quoted strings in a script text. I use this expression : new Regex("\"((?:\\\\.|[^\\\\\"]*)*)\""), e.g "((?:\\.|[^\\\"]*)*)" meanings to not take care of \" cases

This makes RegEx.Matches runs and never stops for some input strings.

Never mind this problem with .Net RegEx, I know my expression is not the best one.

Before, I used (?<!\\)".*?(?<!\\)" expression but it is not enough for "\\" input string.

The aim is to detect quoted strings before I analyze script codes.

Any one would suggest a good expression ?

It has to work for :

echo("Hello" + yourName + ", here is \"MyTest\"");
path = "\\" + file;
echo("path ends with \\");

(beware, \ are strangely edited with this site)

Thanks a lot.

edid
  • 21
  • 2
  • Can you please put the regex into it's own line and preceed it with four leading spaces? Elseway, Nobody can understand what you're actually trying to say us. – fuz Sep 04 '10 at 09:54

1 Answers1

1

Usually it is matched using

"((?:[^\\"]|\\.)*)"

See http://www.ideone.com/JiJwa.

kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
  • tested with http://regexlib.com/RETester.aspx, your expression does not work with the given code in my question. – edid Sep 04 '10 at 10:03