You are viewing a plain text version of this content. The canonical link for it is here.
Posted to regexp-user@jakarta.apache.org by Nino Walker <ni...@xtime.com> on 2001/06/27 18:39:56 UTC
Troubles w/ regexp...
Hi,
I'm trying to match/parse US zip codes, and have problems with the
following expression:
^(\\d{5})[- ]*(\\d{4})?$
This works:
99999
99999-2222
This doesn't:
99999 2222
I've tested this w/ Perl5, and it works...
Thanks in advance,
Nino
Re: Troubles w/ regexp...
Posted by Nino Walker <ni...@xtime.com>.
I just found one working combination:
^(\\d{5})(\\s*-?\\s*)(\\d{4})?$
I'm still puzzled why the other exprs didn't work...
Nino Walker wrote:
> I've tried that too... it doesn't work either.
>
> Some of the things I've tried:
> ^(\\d{5})(\\s*-\\s*)?(\\d{4})?$
> ^(\\d{5})[-\\s]*(\\d{4})?$
> ^(\\d{5})(\\s*-?\\s*)?(\\d{4})?$ - results a null pointer exception.
>
> And they all work w/ perl.
>
> "--==c.g.==--" wrote:
>
> > Hi !
> >
> > It should work,
> > but hav you ever tried the predifiend Whitespace Character Class \s.
> >
> > ^(\\d{5})[-\\s]*(\\d{4})?$
> >
> > ----- Original Message -----
> > From: "Nino Walker" <ni...@xtime.com>
> > To: <re...@jakarta.apache.org>
> > Sent: Wednesday, June 27, 2001 6:39 PM
> > Subject: Troubles w/ regexp...
> >
> > > Hi,
> > >
> > > I'm trying to match/parse US zip codes, and have problems with the
> > > following expression:
> > >
> > > ^(\\d{5})[- ]*(\\d{4})?$
> > >
> > > This works:
> > > 99999
> > > 99999-2222
> > >
> > > This doesn't:
> > > 99999 2222
> > >
> > > I've tested this w/ Perl5, and it works...
> > >
> > > Thanks in advance,
> > >
> > > Nino
> > >
> > >
> > >
Re: Troubles w/ regexp...
Posted by Nino Walker <ni...@xtime.com>.
I've tried that too... it doesn't work either.
Some of the things I've tried:
^(\\d{5})(\\s*-\\s*)?(\\d{4})?$
^(\\d{5})[-\\s]*(\\d{4})?$
^(\\d{5})(\\s*-?\\s*)?(\\d{4})?$ - results a null pointer exception.
And they all work w/ perl.
"--==c.g.==--" wrote:
> Hi !
>
> It should work,
> but hav you ever tried the predifiend Whitespace Character Class \s.
>
> ^(\\d{5})[-\\s]*(\\d{4})?$
>
> ----- Original Message -----
> From: "Nino Walker" <ni...@xtime.com>
> To: <re...@jakarta.apache.org>
> Sent: Wednesday, June 27, 2001 6:39 PM
> Subject: Troubles w/ regexp...
>
> > Hi,
> >
> > I'm trying to match/parse US zip codes, and have problems with the
> > following expression:
> >
> > ^(\\d{5})[- ]*(\\d{4})?$
> >
> > This works:
> > 99999
> > 99999-2222
> >
> > This doesn't:
> > 99999 2222
> >
> > I've tested this w/ Perl5, and it works...
> >
> > Thanks in advance,
> >
> > Nino
> >
> >
> >
Re: Troubles w/ regexp...
Posted by "--==c.g.==--" <cg...@gmx.de>.
Hi !
It should work,
but hav you ever tried the predifiend Whitespace Character Class \s.
^(\\d{5})[-\\s]*(\\d{4})?$
----- Original Message -----
From: "Nino Walker" <ni...@xtime.com>
To: <re...@jakarta.apache.org>
Sent: Wednesday, June 27, 2001 6:39 PM
Subject: Troubles w/ regexp...
> Hi,
>
> I'm trying to match/parse US zip codes, and have problems with the
> following expression:
>
> ^(\\d{5})[- ]*(\\d{4})?$
>
> This works:
> 99999
> 99999-2222
>
> This doesn't:
> 99999 2222
>
> I've tested this w/ Perl5, and it works...
>
> Thanks in advance,
>
> Nino
>
>
>