[Cialug] OT: can somebody help me with a regular expression?

Nathan C. Smith nathan.smith at ipmvs.com
Fri Jul 25 22:23:06 CDT 2008


Is this- (|D|PP) Nothing, or D or PP ?  Interesting.

Yeah, 0 probably should be a possibility.

Thank-you for your help with this little puzzle.

-Nate

> -----Original Message-----
> From: cialug-bounces at cialug.org
> [mailto:cialug-bounces at cialug.org] On Behalf Of Chris Freeman
> Sent: Friday, July 25, 2008 10:14 PM
> To: Central Iowa Linux Users Group
> Subject: Re: [Cialug] OT: can somebody help me with a regular
> expression?
>
> On Fri, Jul 25, 2008 at 4:39 PM, Todd Walton
> <tdwalton at gmail.com> wrote:
>
>
>       On Fri, Jul 25, 2008 at 3:07 PM, Chris Freeman
> <cwfreeman at gmail.com> wrote:
>       > \b(|D|PP)\d{1,3}(,{0,1}\d{3})*
>
>
>       You'll miss the first 999 patents.  I'm guessing that's
> not gonna
>       matter, but couldn't you make character 13 above be a
> zero instead of
>       a one?
>
>
>
> I'm not sure how it's going to miss the first 999 patents. It
> matches 88, and 999, etc, just fine in my tests.
>
> But, \b also matches a comma, so you'd need something like:
> (\s|^)(|D|PP)\d{1,3}(,{0,1}\d{3})*(\s|$)
>
> I'm using "\s" to match spaces, which may not be a valid assumption.
> However, it does correctly match all of the examples set
> forth (including 1, 12, and 123).
>
> Chris
>
> $ cat tmp.pl
> #!/usr/bin/perl
> while(<STDIN>) {
>     if( $_ =~ /(\s|^)(|D|PP)\d{1,3}(,{0,1}\d{3})*(\s|$)/ ) {
>         print "Match\n";
>     } else {
>         print "No match\n";
>     }
> }
>
> $ perl tmp.pl
> 1
> Match
> A1
> No match
> D1
> Match
> PP1
> Match
> 12
> Match
> A12
> No match
> D12
> Match
> PP12
> Match
> 123
> Match
> A123
> No match
> D123
> Match
> PP123
> Match
> 1234
> Match
> A1234
> No match
> D1234
> Match
> PP1234
> Match
> 1,234
> Match
> A1,234
> No match
> D1,234
> Match
> PP1,234
> Match
> 12,345,678
> Match
> A12,345,678
> No match
> D12,345,678
> Match
> PP12,345,678
> Match
> 12,34,56
> No match
> 12,345,678,
> No match
>
>
>
>
>


More information about the Cialug mailing list