Aug 20, 2015
Aug 19, 2015
Regex - Match only first occurence
In UTF-8 HTML text like this :
First,
Second
To achieve this use non greedy expression ?. Basically after you state what is pattern and how often it occurs by using ? you want to limit search only to first occurence.
Example regex with UTF8 greedy expression:
<table>; you want to parse out list of two rows.
<tr class="dummy">
First
</tr>
<tr class="foo">
Second
</tr>
</table>
First,
Second
To achieve this use non greedy expression ?. Basically after you state what is pattern and how often it occurs by using ? you want to limit search only to first occurence.
Example regex with UTF8 greedy expression:
(?<=tr\sclass="\w+">)+?(?>\P{M}\p{M}*)+?(?:\<\/tr\>)+?http://stackoverflow.com/questions/2503413/regular-expression-to-stop-at-first-match
Aug 13, 2015
Aug 11, 2015
Aug 6, 2015
RePost : C# - using statement tips
When using any class that implements IDisposable it is advisable to use using statement.
Now what I didn't know is that using statement is replacement for try finally with call to dispose.
Furthermore call to dispose internally calls Close() for Streams I think.
So using statement is real champion :)
Instead of:
try{
Stream s = new Stream();
}
finally
{
s.Flush();
s.Close();
s.Dispose();
}
Just this:
using ( Stream s = new Stream())
{
}
Important!
Flush() is NOT called automatically !
So using takes care of connections and resources but does not takes care that your data will be flushed from cache.
This makes sense since it primary protects from exceptions and developer should think about Flush().
http://stackoverflow.com/questions/911408/does-stream-dispose-always-call-stream-close-and-stream-flush
Now what I didn't know is that using statement is replacement for try finally with call to dispose.
Furthermore call to dispose internally calls Close() for Streams I think.
So using statement is real champion :)
Instead of:
try{
Stream s = new Stream();
}
finally
{
s.Flush();
s.Close();
s.Dispose();
}
Just this:
using ( Stream s = new Stream())
{
}
Important!
Flush() is NOT called automatically !
So using takes care of connections and resources but does not takes care that your data will be flushed from cache.
This makes sense since it primary protects from exceptions and developer should think about Flush().
http://stackoverflow.com/questions/911408/does-stream-dispose-always-call-stream-close-and-stream-flush
RePost: Naming conventions by Microsoft
Good reading for which I never found time. Yet it is always subject of furious discussion with fellow programmers.
https://msdn.microsoft.com/en-us/library/ms229002(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/ms229002(v=vs.110).aspx
Subscribe to:
Posts (Atom)