tags:

views:

103

answers:

1
+2  A: 

You should be able to achieve this with a "lazy" (compared to the default "greedy") ?. Try this:

Regex regex = new Regex(@"(?<g1>a?)(?<g2>a?)(?<g3>b??)(?<g4>b?)");
Lucero
But there appeared another problem. If this regular expression is applied to 'aabb' I get g1 -> 'a', g2 -> 'a', g3 -> '', g4 -> 'b';but not g1 -> 'a', g2 -> 'a', g3 -> 'b', g4 -> 'b'. I need the second variant.
StuffHappens
@Stuff - use `^(?<g1>a?)(?<g2>a?)(?<g3>b??)(?<g4>b?)$` . You're allowing the regex to capture a part of your string.
Kobi
Thanks Kobi, that's what I would have suiggested to Stuff also.
Lucero