tags:

views:

63

answers:

2

Hi, 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.

+1  A: 

Usually it is matched using

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

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

KennyTM
tested with http://regexlib.com/RETester.aspx, your expression does not work with the given code in my question.
edid
@edid: Then you tested it wrongly.
KennyTM
(beware, \ are strangely edited with this site)
edid