Simple Regex question / multiple matches?

The collection returned by Matches contains consecutive matches, not alternative matches for the same section of the string. So if you pass in a string like "A = B\nC = D", you'll get back two matches: one for "A = B" and one for "C = D" (as does not match line breaks).

The collection returned by Matches contains consecutive matches, not alternative matches for the same section of the string. So if you pass in a string like "A = B\nC = D", you'll get back two matches: one for "A = B" and one for "C = D" (as . Does not match line breaks).

The . * is normally greedy. This means it matches as many characters as possible whilst satisfying the expression.

Therefore the first . * matches the "A = B", leaving the "C" for the second . * You can change the behaviour using a?

After the expression. . *?

Will match as few characters as possible whilst satisfying the expression.

Regular expressions work in such a way that when a match is found, the part of the input that has been matched already is ignored from then on. So when A = B has been matched, that part of the input will not be subject to any more matching.

Basically the dot is greedy (will match anything apart from new lines), and will match all enclosing ")", and not back track until it's found the last matching ")". You should probably be more specific, and use something like "\w" instead of ". " or else a negation, "^()" etc.Check this out for more info.

regular-expressions.info/dot.html.

It is the asterisk that is greedy, not the dot – qbert220 Mar 21 at 16:21 I think you mean, the star (*) is greedy... – Roly Mar 21 at 16:21 The question wasn't why the regex matches to the end, but why Matches does not return all possible ways in which the string could be matched to the end. Note that in the output which the OP expected, both matches go to the end of the string as well. – sepp2k Mar 21 at 16:25.

(^=?)" then you would get multiple results. Please read documentation! :-D.

With this type of answer, links would be helpful... – Austin Salonen Mar 21 at 16:21 Check out this: radsoftware.com. Au/regexdesigner it is a good tool to design and edit Regex in C# and has built in help. – Varun Chatterji Mar 21 at 16:34.

The * quantifier is greedy. It makes the first expression . * matches many chars as possible, so, the expression will always match (A = B) = (C).

Using the not greedy quantifier *? Will match (A) = (B = C). Try using it!

This means it matches as many characters as possible whilst satisfying the expression. Therefore the first . * matches the "A = B", leaving the "C" for the second .

You can change the behaviour using a? After the expression.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions