tags:

views:

36

answers:

1

I have this regular expression in c#:

Regex oRegex_ = new Regex("<!-- #BeginEditable \"Body\"[^>]*>(.*)<!-- #EndEditable [^>]*>", RegexOptions.Multiline);
MatchCollection matches_ = oRegex_.Matches(contents);

The variable called 'contents' equals this:

<!-- #BeginEditable "Body" -->First String<!-- #EndEditable --><!-- #BeginEditable "Extra" -->Second String<!-- #EndEditable -->

Currently it doesnt seem to grab what i need, which is

'First String'

Instead it grabs

'First String<!-- #EndEditable --><!-- #BeginEditable "Extra" -->Second String<!-- #EndEditable -->'

Can anyone help me solve this using a regular expression? :(

Please Note: i will be replacing 'Body' to become a variable and then put it all in a loop so i can extract 'Second String' by making the variable equal 'Extra'.

+2  A: 

Do a non greedy catch using *?:

<!-- #BeginEditable \"Body\"[^>]*>(.*?)<!-- #EndEditable [^>]*>

Another option is to catch the right character (not <, but this is less accurate if you allow <s in your body):

<!-- #BeginEditable \"Body\"[^>]*>([^<]*)<!-- #EndEditable [^>]*>
Kobi
Excellent that did the trick! Thank you a million times over! You saved me from extreme depression!
Stephen
Great! Because you have to watch over your health. That's what's really important :) . Happy to help.
Kobi