edid
edid

Reputation: 21

RegEx : (double)quoted strings

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.

Upvotes: 0

Views: 895

Answers (1)

kennytm
kennytm

Reputation: 523214

Usually it is matched using

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

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

Upvotes: 1

Related Questions