开发者

How do I get a path between quotes using regex in C#?

I have a path between quotes that needs to be captured. I am very new to regular expressions and need some help figuring out how to do this.

Edit:

Sorry for not posting the string in the first place. that was silly of me. Here is the string:

"C:\Users\wner\Dropbox\Work\rts\rts\bin\Debug\rts.dll"

Now this is preceded 开发者_如何学Pythonby other strings and is followed by other strings, but I am able to single this out, however I do need the string within the quotes.


If you want to remove quote before and after your string:

string path = inputString.Trim('"');

If you want to remove all quotes:

string path = inputString.Replace("\"", "");


We need to see some code really, it sounds like your trying to do this???

string path = yourpathstring.Replace("\"", "");

This will remove the quotes and leave you with the path, not sure if this is what you want until there is some code.


If regular expressions aren't required, you can you string.Split.

var split = path.Split("\"", StringSplitOptions.RemoveEmptyEntries);
var unquotedPath = split[0];


You haven't given much to go off of but this will do a non-greedy match of content between two double quotes:

"[^"\r\n]*"

So for the string:

this "is\something" a test "again\something\else"

It would match is\something and again\something\else.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜