Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.help > #1968

Re: Regexp help

From Gene Wirchenko <genew@ocis.net>
Newsgroups comp.lang.java.help
Subject Re: Regexp help
Date 2012-08-08 12:13 -0700
Organization A noiseless patient Spider
Message-ID <99e528d5rjt3a0ahl6bpgih7ih1gv68k26@4ax.com> (permalink)
References <3e0aa0ea-bdb5-4cd5-bdae-4fcd31c70a7f@googlegroups.com> <jVfUr.51896$ls7.32117@newsfe11.iad> <e8fd1c92-6f54-48ee-8cc9-ec5a10d03ce5@googlegroups.com> <HcwUr.685$CE7.526@newsfe12.iad> <jvu6tp$gec$1@dont-email.me>

Show all headers | View raw


On Wed, 08 Aug 2012 10:16:37 -0700, markspace <-@.> wrote:

[snip]

>There's a quote that sometimes goes around the internet, something like 
>this: "Sometimes a programmer who is confronted with a problem solves it 
>with regex.  Now the programmer has two problems."

Some people, when confronted with a problem, think "I know, I'll use
regular expressions."  Now they have two problems.

>Regex is not the sharpest tool in the programmers toolbox.  It was 
>intended to be used once, on a command line like with the grep tool, and 
>then tossed away.

     Yes.

     No.

>Take the time to write a parser to do what you want.  It'll probably be 
>faster both ways:  you could write a parser faster than trying to figure 
>out what regex you need to use, and regex is interpreted, whereas 
>parsers can be optimized directly to machine code.  Win-win, and that's 
>before taking into account the trouble maintenance programmers will have 
>deciphering this regex.

     A bit of devil's advocate: I like regexes, but simple regexes.  I
have some JavaScript code where I could have used one giant regex to
process, but I instead chose to use simple regexes and a bit of
processing.  It is a lot more readable than a custom parser.  The
giant regex would have been a ball of mud though.

     Regexes do not do so well on error handling.  Either the input
matches the regex or not, but you might want to know why it does not
match.  For those cases, I write a finite state machine.

Sincerely,

Gene Wirchenko

Back to comp.lang.java.help | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Regexp help mike <mikaelpetterson@hotmail.com> - 2012-08-07 07:03 -0700
  Re: Regexp help Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-08-07 14:38 -0700
    Re: Regexp help mike <mikaelpetterson@hotmail.com> - 2012-08-07 22:14 -0700
      Re: Regexp help Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-08-08 09:11 -0700
        Re: Regexp help markspace <-@.> - 2012-08-08 10:16 -0700
          Re: Regexp help Gene Wirchenko <genew@ocis.net> - 2012-08-08 12:13 -0700
            Re: Regexp help markspace <-@.> - 2012-08-08 14:15 -0700
              Re: Regexp help Gene Wirchenko <genew@ocis.net> - 2012-08-08 18:43 -0700

csiph-web