vb.net regex
I have some strings like this to analyze:
<%JohnSmith$>@ some other text @<%FredJonese%>@ (@<%SallyHarris%>@)@
I need to find occurrences of each block of text that's between <% and %> and also those between each pair of @ symbols.
So for the above example, I want to retrieve the following 6 pieces of text (there is a leading space in the 2nd and 4th lines below):
JohnSmith
some other text
FredJones
(
SallyHarris
)
When I use a patter like "<%\w%> it retrieves the entire line because the line starts and ends with &开发者_Go百科lt;% and %>
I'm lost on the best way to do this. I need to get the chunks out in the order in which they occur.
Nothing I've tried so far is working. I know I could write a loop that goes through the string character by character but it seems like regex can handle this. Can anyone help out on this?
Thanks.
You need to add the lazy operator after a star or a plus (lazy star or lazy plus). If you don't, the matching is greedy (the default) so it tries to match as much as possible.
<%\w*?%>
Notice the question mark. This will match all three.
精彩评论