Re: function to match parenthesis '(' and ')'
- From: "Ludovic SOEUR" <Ludovic_SOEUR@xxxxxxxxxxx>
- Date: Tue, 25 Oct 2005 09:30:14 +0200
Thanks all for all your comments about this debate. That 's very interesting
to see all these points of view.
I agree on all everybody have said since the beginning except for 2 things :
1) You say that in ten lines, you are able to write something that can say
if the balance matching is correct. You did not say how many lines it takes
to have a collection with all matching subelements. Again, in one line, that
is done. Do you know why there is XPath for xml ? To simplify treatment for
selecting a node. In one line, you can reach the nodes you wanted without
rewritting the same similar code may times. I consider it's the same with
Regex.
2) There some case about little changes where the regex modification is
quicker than a code like marcus' one. If instead of evaluating expression
with only parenthesis, you want to find all arguments of a function in a
dynamical compilation of a source code. You only have to add the name of the
function between the first parenthesis to match. With a code like marcus's
one, you will have to write a string parser wich is already implemented in
regex.
Seeing all you replies, I modify what I said at the beginning of this
debate. Maybe only for matching parenthesis, it's better not to use regex.
When you have to add parsing with the parenthesis matching, I'm sure that
regex is the proper tool.
P.S. Michael : I could not stop laughting seeing your reply about me. Why
not try to work in the same company ? It should be very interesting.... ;-)
Ludovic.
"Jon Skeet [C# MVP]" <skeet@xxxxxxxxx> a écrit dans le message de
news:MPG.1dc725f59f46dfba98c99d@xxxxxxxxxxxxxxxxxxxxxxx
> Ludovic SOEUR <Ludovic_SOEUR@xxxxxxxxxxx> wrote:
> > > I certainly appreciate that regexes are useful. I just don't think
this
> > > is a place where they're suitable. I would guess that at least half of
> > > the requests for regular expressions I see on the newsgroups are
> > > inappropriate places to apply regular expressions. A lot of people
seem
> > > to approach any textual problem with the immediate idea of "use a
> > > regular expression!" without considering whether or not it's the
> > > best/simplest way of solving it.
> >
> > Yes, I agree with you. that is a good summary of Regex usage today.
> > I will however add, for this topic (validating and parsing expressions
with
> > parenthesis), that a known regex does all the job requested.
> > Of course you can write code, write your own libraries that should be
more
> > elegant (it depends on what you think is elegant). I prefer reuse what
is
> > already done and only optimise it if necessary.
>
> You had to go to a web page to find that code. I'm sure you *could*
> have found something like Marcus's code on a web page. Alternatively,
> the code that Marcus wrote was easy to write in the first place - no
> need to hunt it down.
>
> Given the option of "look for something that someone else has done,
> which I (and anyone reading the code) will need to put significant
> effort into understanding" and "write something from scratch in about
> 10 lines of easily understandable code" I'll pick the second one every
> time.
>
> --
> Jon Skeet - <skeet@xxxxxxxxx>
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too
.
- References:
- function to match parenthesis '(' and ')'
- From: Steve Kirsch
- Re: function to match parenthesis '(' and ')'
- From: Kevin Spencer
- Re: function to match parenthesis '(' and ')'
- From: Jon Skeet [C# MVP]
- Re: function to match parenthesis '(' and ')'
- From: Kevin Spencer
- Re: function to match parenthesis '(' and ')'
- From: Jon Skeet [C# MVP]
- Re: function to match parenthesis '(' and ')'
- From: Ludovic SOEUR
- Re: function to match parenthesis '(' and ')'
- From: Jon Skeet [C# MVP]
- function to match parenthesis '(' and ')'
- Prev by Date: Re: using a frame of an animated gif pic.
- Next by Date: Re: How to understand the use of namespaces ...
- Previous by thread: Re: function to match parenthesis '(' and ')'
- Next by thread: Re: function to match parenthesis '(' and ')'
- Index(es):
Relevant Pages
|