On Oct 19, 9:02 am, natebrun...@gmail.com wrote:
I wrote this regex
<font>.*\((?<Inside>.*?)\)</font>
"<font(Hi there)</font></font><font(Hi there)</font><font(Hi
there)</font><font(Hi there)</font><font(Hi there)</font>"
However it only returns the whole thing
<font(Hi there)</font></font><font(Hi there)</font><font(Hi
there)</font><font(Hi there)</font><font(Hi there)</fontas a
Single match
Any ideas on how I can do a non-greedy match ? Thanks!
Nate
Say I was looking for the shortest "quoted string".
99% of the time I write something like this to find the smallest
match:
Regex regex = new Regex("\"([^\"]*)\"");
This will find a quote, and pull until it sees another quote, then the
quote. This can be extended to something more like you are looking
for.
Regex regex = new Regex(".*\((?<Inside>[^\)]?)\)");
You see, it will look until it finds a ). You just need to make sure
that you don't have any ) inside.