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


Groups > comp.lang.java.programmer > #5096

Re: Confusion about String.matches method

From Gene Wirchenko <genew@ocis.net>
Newsgroups comp.lang.java.programmer
Subject Re: Confusion about String.matches method
Date 2011-06-08 07:50 -0700
Organization A noiseless patient Spider
Message-ID <n52vu6h7ap9a90215oolj9dpfd88ifvd4p@4ax.com> (permalink)
References (4 earlier) <2fd869d6-c2f6-4360-85b4-6df2b6e68fb0@p13g2000yqh.googlegroups.com> <94n2jpFa1oU1@mid.individual.net> <ig1pu6dqcs402grnpe9kpa92lit9ts7os9@4ax.com> <4deca972$0$12380$c30e37c6@exi-reader.telstra.net> <crttu6djrpeks89rc2qomltb1bjtancbt0@4ax.com>

Show all headers | View raw


On Tue, 07 Jun 2011 21:18:54 -0700, Roedy Green
<see_website@mindprod.com.invalid> wrote:

[snip]

>The problem with regexes is all it takes is one char off an the whole
>thing does not work.  You have no clue where the problem is.  You
>rarely find errors with syntax checking. There is no trace.
>The other problem is a regex will work 90% of the time.  It may be
>quietly rejecting a small percentage of the strings, and you might not
>notice.

     There are more problems than that.

     I assume that you are familiar with this quote:
Some people, when confronted with a problem, think "I know, I'll use
regular expressions."   Now they have two problems.

     I find regexes to be less than totally useful.  I sometimes have
to define a format string with substitution parameters.  Here is an
example:
Per client's instruction, the total of all invoices for the current
month will be charged against the supplied credit card number on %D
unless we hear otherwise prior to that date.

     The date gets substituted for the %D.  There are a few rules.
There must be one and only "%D" string.  "%" is an escape character
and is doubled for the literal "%".

     I could write a regex for this, BUT I also have to have a routine
for executing the string substitution, and regexes do not help with
this.  I do not want two rather different versions of the code.  (As
it is, I have two versions of code that are somewhat similar.)  More
importantly, if one routine gets changed, so should the other, and it
should be obvious how to do it.

     If I wanted to add a second variable to the example above, say a
contact name, and wanted the constraint of appearing once and only
once, using a regex would get even uglier.

     I could use regexes for such things as validating with no
interpretation, but such data that I have to validate usually has
trivial formatting.  For example, a Canadian Postal Code is "A9A 9A9"
with some limitations on the alphabetic characters.  A regex would be
overkill.

Sincerely,

Gene Wirchenko

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


Thread

Confusion about String.matches method laredotornado <laredotornado@zipmail.com> - 2011-05-31 10:24 -0700
  Re: Confusion about String.matches method Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-05-31 17:28 +0000
    Re: Confusion about String.matches method laredotornado <laredotornado@zipmail.com> - 2011-05-31 13:15 -0700
      Re: Confusion about String.matches method Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-05-31 23:10 +0200
      Re: Confusion about String.matches method Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-05-31 21:26 +0000
      Re: Confusion about String.matches method Ian Shef <invalid@avoiding.spam> - 2011-05-31 22:20 +0000
      Re: Confusion about String.matches method Roedy Green <see_website@mindprod.com.invalid> - 2011-05-31 15:53 -0700
        Re: Confusion about String.matches method laredotornado <laredotornado@zipmail.com> - 2011-06-01 07:10 -0700
          Re: Confusion about String.matches method Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-06-01 16:02 +0100
            Re: Confusion about String.matches method Roedy Green <see_website@mindprod.com.invalid> - 2011-06-06 00:50 -0700
              Re: Confusion about String.matches method Esmond Pitt <esmond.pitt@bigpond.com> - 2011-06-06 20:18 +1000
                Re: Confusion about String.matches method Roedy Green <see_website@mindprod.com.invalid> - 2011-06-07 21:15 -0700
                Re: Confusion about String.matches method Michael Wojcik <mwojcik@newsguy.com> - 2011-06-08 11:13 -0400
                Re: Confusion about String.matches method Esmond Pitt <esmond.pitt@bigpond.com> - 2011-06-09 19:19 +1000
                Re: Confusion about String.matches method Roedy Green <see_website@mindprod.com.invalid> - 2011-06-07 21:18 -0700
                Re: Confusion about String.matches method Gene Wirchenko <genew@ocis.net> - 2011-06-08 07:50 -0700
              Re: Confusion about String.matches method Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-06-06 12:15 +0100
          Re: Confusion about String.matches method Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-06-01 11:17 -0400
            Re: Confusion about String.matches method Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-06-01 18:59 +0200
          Re: Confusion about String.matches method Ian Shef <invalid@avoiding.spam> - 2011-06-01 19:41 +0000
      Re: Confusion about String.matches method Jim Janney <jjanney@shell.xmission.com> - 2011-06-01 08:41 -0600

csiph-web