Re: regex syntax

Tech-Archive recommends: Fix windows errors by optimizing your registry



jg wrote:

I did find the pattern string getting too huge. So I started to split date pattern into 3 components before using them to compose the final pattern, although I did not use the string format method.

Well, if you ask me, you should always use String.Format when putting together strings from more than two parts. A String.Format call can create an arbitrarily complicated string in one operation, while a concatenation a + b + c takes two operations at least. Strings are immutable in .NET, so a + b + c will end up allocating several new strings before the final result is ready.


The argument against this is that the compiler might get rid of some of the overhead for you, at least when a, b and c are static strings. But I don't like to depend on that, especially when the String.Format call is usually so much better readable:

"At " + time.ToString() + ", the user " + user + "had a problem accessing the " + resource + "resource."

String.Format("At {0}, the user {1} had a problem accessing the {2} resource.", time, user, resource);



               Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
.



Relevant Pages

  • Re: OT: novice regular expression question
    ... > data record begins with either a string, or a list of strings. ... If the format is "Python strings and lists of ... "negative lookbehind assertion" - in other words, a pattern that doesn't ... Let's try matching a single string first: ...
    (comp.lang.python)
  • Re: OT: novice regular expression question
    ... >> data record begins with either a string, or a list of strings. ... If the format is "Python strings and lists of ... Then use that pattern, parenthesized to turn it ... > Let's try matching a single string first: ...
    (comp.lang.python)
  • Re: Java vs. Pascal
    ... Ich meine nur dass wenn Strings ... so beginnt der Garbage Collector zu laufen. ... Aber das wiederverwenden von Pattern und Matcher spart unter anderem ... 18s Laufzeit, davon ca. 2s GC ...
    (de.comp.lang.java)
  • Re: regexp pattern problems
    ... comes to syntax hilighting i got problems defining a pattern (which is ... The pattern for strings is at the moment (if you don't want to open ... the widget and run the regexp command? ...
    (comp.lang.tcl)
  • Re: Need better string methods
    ... Here is the simplest design pattern so far (taking the suggestions of ... The use of regular expressions allows a pattern like the above code ... methods to simplify working with lists of strings. ...
    (comp.lang.python)