c# Regex trouble

Posted by Shannow on Stack Overflow See other posts from Stack Overflow or by Shannow
Published on 2010-12-21T14:17:57Z Indexed on 2010/12/21 14:54 UTC
Read the original article Hit count: 685

Filed under:

Hi there,

I'm having a bit of trouble with my regex.

String a = @"{target=}jump";
String b = "continue";
String c = "jump";
String d = @"{target=intro}jump";
String e = "prev";
String f = @"{target=}choice";
String g = @"{target=intro}choice";
String h = "choice";
String i = "previous";
String j = @"{target=intro}continue";
String k = "cont";
String l = @"{target=}continue";
Regex regex = new Regex(@"(^{target=(\w.*)}(choice|jump))|(^[^.]*(continue|previous))");
var a_res = regex.IsMatch(a);
var b_res = regex.IsMatch(b);
var c_res = regex.IsMatch(c);
var d_res = regex.IsMatch(d);
var e_res = regex.IsMatch(e);
var f_res = regex.IsMatch(f);
var g_res = regex.IsMatch(g);
var h_res = regex.IsMatch(h);
var i_res = regex.IsMatch(i);
var j_res = regex.IsMatch(j);
var k_res = regex.IsMatch(k);
var l_res = regex.IsMatch(l);

Basically what i need is to get a match when choice or jump is present that it is proceeded by {target= } with any number of characters after the =. And also to match if continue or previous are present but only if they are proceeded by nothing.

so A = false, b = true, c = false, d = true, e = false, f = false, g = true, h = false, i = true, j = false, k = false and l = false,

with my regex above I get correct reading for everything bar j and l.

Can anyone please help?

© Stack Overflow or respective owner

Related posts about c#

Related posts about regex