Re: Search for multiple things in a string



Jon Skeet [C# MVP] wrote:

In a hurry, I can very easily see someone changing a string literal
from one thing to another, not noticing that as it's a regular
expression, they need to escape part of their new string.

In a hurry, all kinds of things can happen when making changes to source code.


Now, where's the advantage of using regular expressions in this case?

I wasn't saying there was one in the specific scenario the OP introduced. I was using the example to show that regular expressions don't have to be any more complicated than simple string operations.


About IndexOf, as I meant to say already, as long as the problems you're
trying to solve are the kind that can be solved with those simple string
functions (and without resulting in huge algorithms), you'll probably have
the performance argument on your side anyway.

Well, I'm much keener on the readability argument than the performance one - I suspect that the performance difference would rarely be of overall significance.

As I'm trying to say all the time, as soon as an implementation reaches a complexity that makes it worth thinking about regular expressions, I'm sure an alternative solution based on simple string functions won't be more readable any longer. I'd even go so far as to say that as soon as more than one call to a simple string function is needed for a given problem, most probably I'll find the regular expression solution more readable. This is, after all, a subjective decision to make.



Oliver Sturm -- Expert programming and consulting services available See http://www.sturmnet.org (try /blog as well) .



Relevant Pages

  • Re: Get regular expression
    ... own tree structure. ... Expression compares a string character-by character, ... regular expression solution, which was about as close as one could get to ... the structure of the hierarchy can be inferred by using ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Get regular expression
    ... regular expression solution, which was about as close as one could get to ... first string. ... explode "ABLATION" and see subnodes of "ENDOMETRIAL ... "Heart 27.33/2" ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Regular expression optimization
    ... position in the replacement array of strings, ... > input string and a MatchEvaluator delegate. ... > The first part required combining the separate Regular Expression strings ...
    (microsoft.public.dotnet.general)
  • Small regular expression parser
    ... the goal was to develop a very simple regular expression parser. ... sets are selected using the % character instead of \. ... into the string of the start of the match and the length of the match. ... Last there are a couple macros to help with captures. ...
    (comp.lang.lisp)
  • Re: Which RegEx Testing Tool Do You Prefer?
    ... * Regular Expression Tester ... > match has been returned prior to the end of the string. ... >> a white space although in a manner that is confusing as I will point out ... >> would ignore those previous white space characters and then report 2:? ...
    (microsoft.public.dotnet.framework.aspnet)

Loading