I have this regular expression in c#:
Regex oRegex_ = new Regex("<!-- #BeginEditable \"Body\"[^>]*>(.*)<!-- #EndEditable [^>]*>", RegexOptions.Mu开发者_高级运维ltiline);
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'.
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 [^>]*>
精彩评论