开发者

How to get regular expression matches between two boundaries

I have the following text:

started: Project: ProjectA, Configuration: Release Any CPU ------

I would like to get just the actual project name which in this example is "ProjectA".

I do have a regular expression "started:(\s)Project:(\s).*," which will give me "started: Project: ProjectA," and then I can use further basic string searching to return the project name but wa开发者_StackOverflow中文版s wondering if there is any way I can just grab the actual project name without doing the extra string searching, maybe using a correct regular expression.

What I need is the string value between boundaries "started: Project: " and ",".

Any ideas?


Try this: started:\sProject:\s(.*),. I also recommend that you install Expresso. This is an excellent tool to debug and analyze regular expressions.


You can use "started: Project: ([^,]+)," and then get the value of the first group:

var m = regex.Match("....");
string project = m.Groups[1].Value;


If a project name cannot contain a comma, this should work:

started:\sProject:\s(.*?),
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜