开发者

C#: Compare a Regex string with groups

I have this string: {test1}-{test2}/{x+y}

I want to check whether {test1}{test} matches that string.

It WOULD match if I jus开发者_如何学Ct could ignore the chars between the }...{

How would you write that Regex?

UPDATE:

I want to check whether {test1}{test2}{x+y} matches the string:

{test1}-{test2}/{x+y}


I am assuming your comment means that you want to use the following pattern {test1}{test2}{x+y} and you want it to match the first string, with the additional rule that between the braced groups you can provide anything, so the minus and the division there should not prevent a match.

To match the input, which can contain arbitrary characters between the braced groups, use this type of regular expression:

\{test1\}.*\{test2\}.*\{x\+y\}

This will match:

{test1}{test2}{x+y}
{test1}-{test2}/{x+y}

{test1}+{test3}*{test2}/{test4}-{x-y}+{x+y}
       ---------       ---------------           <-- the parts that match .*
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜