[28554] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 9918 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 1 21:10:17 2006

Date: Wed, 1 Nov 2006 18:10:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 1 Nov 2006     Volume: 10 Number: 9918

Today's topics:
        reg exact string matching <arvindkannan1@gmail.com>
    Re: reg exact string matching <someone@example.com>
    Re: regular expression consecutive numbers or letters <tzz@lifelogs.com>
    Re: regular expression consecutive numbers or letters <wahab@chemie.uni-halle.de>
    Re: regular expression consecutive numbers or letters mchesak@gmail.com
    Re: regular expression consecutive numbers or letters <nospam-abuse@ilyaz.org>
    Re: regular expression consecutive numbers or letters <nospam-abuse@ilyaz.org>
    Re: regular expression consecutive numbers or letters <nospam-abuse@ilyaz.org>
    Re: regular expression consecutive numbers or letters <attn.steven.kuo@gmail.com>
    Re: Regular Expression Question Why Doesn't this Match? <needin4mation@gmail.com>
    Re: Regular Expression Question Why Doesn't this Match? <needin4mation@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 1 Nov 2006 16:04:51 -0800
From: "sivga" <arvindkannan1@gmail.com>
Subject: reg exact string matching
Message-Id: <1162425891.598759.219620@k70g2000cwa.googlegroups.com>

Hi

how do i match a string exactly for eg

$stringid is pid-3-1

i need to match pid-[0-9*]-[0-9*] and not anything like pid-3-1-1 or
pid-3 ,pid-3-1-1-1 etc

allowed possibilities are

pid-any no of digits-any no of digits

this is the code i have but does not seem to work

if ($stringid eq 'pid-[0-9*]-[0-9*]' ) {
                        print " pid  is correct ...... \n";

              }else {
                        print " pid does not exist  \n";
                        exit 1;
                     }



------------------------------

Date: Thu, 02 Nov 2006 00:25:39 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: reg exact string matching
Message-Id: <7Wa2h.77066$E67.28372@clgrps13>

sivga wrote:
> 
> how do i match a string exactly for eg
> 
> $stringid is pid-3-1
> 
> i need to match pid-[0-9*]-[0-9*] and not anything like pid-3-1-1 or
> pid-3 ,pid-3-1-1-1 etc
> 
> allowed possibilities are
> 
> pid-any no of digits-any no of digits
> 
> this is the code i have but does not seem to work
> 
> if ($stringid eq 'pid-[0-9*]-[0-9*]' ) {

if ( $stringid =~ /\Apid-\d+-\d+\z/ ) {


>                         print " pid  is correct ...... \n";
> 
>               }else {
>                         print " pid does not exist  \n";
>                         exit 1;
>                      }


John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


------------------------------

Date: Wed, 01 Nov 2006 19:31:19 +0000
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: regular expression consecutive numbers or letters
Message-Id: <g69d587arqw.fsf@lifelogs.com>

On  1 Nov 2006, David.Squire@no.spam.from.here.au wrote:

mchesak@gmail.com wrote: > David Squire wrote: >> mchesak@gmail.com wrote:
>>>> I need password validation routine.
>>> So write one.
>>>
>>> This is not a "free code" group. People here will be happy to help you
>>> to improve your code, but not to write it from scratch.
>>
>> If I knew how I would.  I am not even sure where to start.  This seems
>> to be a common password validation issue and maybe some one has already
>> done it.   I could hack a barbaric routine to do this but I was hoping
>> was something more elegant soultion.  If some one would point me in the
>> right direction that would be helpfull,
>
> Have you gone to CPAN and searched for "password"? There is a module
> there that does exactly what you want. Please search the standard Perl
> resources before asking here.

Come on, that's just rude.  Obviously the OP doesn't know much about
Perl.  If you had pointed him to CPAN instead of giving the *bad*
advice to write his own routine, everyone would have been happy.

The posting guidelines don't say you have to write code before asking
a question.  If I'm wrong, please tell me what I've missed in the
guidelines.

>> something your comments are not.
>
> Not true. If you want to get help here, you need to learn how the group
> works. See the posting guidelines that are regularly posted here, and
> also available at
> http://www.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

Good advice.  Unfortunately few people have read these.

Ted


------------------------------

Date: Wed, 01 Nov 2006 21:26:09 +0100
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: regular expression consecutive numbers or letters
Message-Id: <eib057$57$1@mlucom4.urz.uni-halle.de>

Thus spoke mchesak@gmail.com (on 2006-11-01 19:17):
> Mirco Wahab wrote:
> How simple and elegant, thanks for the lesson in Perl.

Sorry for misunderstanding your question.
Now that should work as intended:

   use strict;
   use warnings;

   my @wordlist = qw' 1234 abcd 1a2b c2d4 ';

   my $rgx = qr/. (??{ '(?:'
                       . chr( 1+ord($&))
                       . chr( 2+ord($&))
                       . chr( 3+ord($&))
                       . ')'
                     })/x;

   for (@wordlist) { print "bad: $_\n" if /$rgx/ }


at least for 'ascii-like' stuff, but one xould start
from here ...

Regards

Mirco


------------------------------

Date: 1 Nov 2006 13:44:31 -0800
From: mchesak@gmail.com
Subject: Re: regular expression consecutive numbers or letters
Message-Id: <1162417471.291092.155790@f16g2000cwb.googlegroups.com>


Mirco Wahab wrote:
> Thus spoke mchesak@gmail.com (on 2006-11-01 19:17):
> > Mirco Wahab wrote:
> > How simple and elegant, thanks for the lesson in Perl.
>
> Sorry for misunderstanding your question.
> Now that should work as intended:
>
>    use strict;
>    use warnings;
>
>    my @wordlist = qw' 1234 abcd 1a2b c2d4 ';
>
>    my $rgx = qr/. (??{ '(?:'
>                        . chr( 1+ord($&))
>                        . chr( 2+ord($&))
>                        . chr( 3+ord($&))
>                        . ')'
>                      })/x;
>
>    for (@wordlist) { print "bad: $_\n" if /$rgx/ }
>
>
> at least for 'ascii-like' stuff, but one xould start
> from here ...
>
> Regards
>
> Mirco
That is pretty slick, I spent some time reviewing this and adding
comments, I hope they are correct.  Thanks.

my $rgx = qr/. # Matches any single character except a newline

        (??{   # Dynamic regex, return value used as regex
        '(?:'  # group subexpression without capture
        . chr( 1+ord($&)) # convert to character( 1 + ascii value of
character)
        . chr( 2+ord($&))
        . chr( 3+ord($&))
                       . ')'
                     })/x; # extended regular expression



------------------------------

Date: Wed, 1 Nov 2006 22:57:03 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: regular expression consecutive numbers or letters
Message-Id: <eib8nv$1cjj$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Mirco Wahab 
<wahab-mail@gmx.net>], who wrote in article <eib057$57$1@mlucom4.urz.uni-halle.de>:
> Thus spoke mchesak@gmail.com (on 2006-11-01 19:17):
> > Mirco Wahab wrote:
> > How simple and elegant, thanks for the lesson in Perl.
> 
> Sorry for misunderstanding your question.
> Now that should work as intended:
> 
>    use strict;
>    use warnings;
> 
>    my @wordlist = qw' 1234 abcd 1a2b c2d4 ';
> 
>    my $rgx = qr/. (??{ '(?:'
>                        . chr( 1+ord($&))
>                        . chr( 2+ord($&))
>                        . chr( 3+ord($&))
>                        . ')'
>                      })/x;
> 
>    for (@wordlist) { print "bad: $_\n" if /$rgx/ }

#!/usr/bin/perl -w
# These strings are assumed to not overlap; otherwise different logic is needed
my @prohibited = (['01234567890', 4]); # Add more elements if needed
my $rx = '';
my $set = '';
for my $proh (@prohibited) {
  my ($prohibited, $len) = @$proh;
  for my $pos (0..length($prohibited) - $len) {
    my $ch = quotemeta substr $prohibited, $pos, 1;
    my $ss = quotemeta substr $prohibited, $pos + 1, $len - 1;
    $rx .= "| $ch (?! $ss ) ";
    $set .= $ch;
  }
}
$set = quotemeta $set;
$rx = qr( ^ (?: [^$set] $rx )* $ )ix;
print $rx;

print "Correct1" if     'a12454890x'  =~ $rx;
print "Correct2" unless 'a123454890x' =~ $rx;
__END__


------------------------------

Date: Wed, 1 Nov 2006 23:13:19 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: regular expression consecutive numbers or letters
Message-Id: <eib9mf$1d7g$1@agate.berkeley.edu>

[A complimentary Cc of this posting was NOT [per weedlist] sent to
Ilya Zakharevich 
<nospam-abuse@ilyaz.org>], who wrote in article <eib8nv$1cjj$1@agate.berkeley.edu>:
> # These strings are assumed to not overlap; otherwise different logic is needed
> my @prohibited = (['01234567890', 4]); # Add more elements if needed

Better version:

#!/usr/bin/perl -w
use strict;

# These strings may overlap:
my @prohibited = (['01234567890', 4]); # Add more elements if needed
my %tails;
for my $proh (@prohibited) {
  my ($prohibited, $len) = @$proh;
  for my $pos (0..length($prohibited) - $len) {
    my $ch = quotemeta substr $prohibited, $pos, 1;
    my $ss = quotemeta substr $prohibited, $pos + 1, $len - 1;
    push @{$tails{$ch}}, $ss;
  }
}
my $set = join '', keys %tails;
my %rtails;
$rtails{$_} = join ' | ', @{$tails{$_}} for keys %tails;
my $rx = join ' | ', map " $_ (?! $rtails{$_} )", keys %rtails;
$rx = qr( ^ (?: [^$set] | $rx )* $ )ix;
print $rx;

print "Correct1" if     'a12454890x'  =~ $rx;
print "Correct2" unless 'a123454890x' =~ $rx;
__END__

Yours,
Ilya


------------------------------

Date: Wed, 1 Nov 2006 23:22:20 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: regular expression consecutive numbers or letters
Message-Id: <eiba7c$1dkt$1@agate.berkeley.edu>

[A complimentary Cc of this posting was NOT [per weedlist] sent to
Ilya Zakharevich 
<nospam-abuse@ilyaz.org>], who wrote in article <eib9mf$1d7g$1@agate.berkeley.edu>:
> # These strings may overlap:
> my @prohibited = (['01234567890', 4]); # Add more elements if needed

Same, with a little bit more test patterns:

#!/usr/bin/perl -wl
use strict;

# These strings may overlap:
my @prohibited = (['01234567890', 4],
		  ['31415926', 4],); # Add more elements if needed
my %tails;
for my $proh (@prohibited) {
  my ($prohibited, $len) = @$proh;
  for my $pos (0..length($prohibited) - $len) {
    my $ch = quotemeta substr $prohibited, $pos, 1;
    my $ss = quotemeta substr $prohibited, $pos + 1, $len - 1;
    push @{$tails{$ch}}, $ss;
  }
}
my $set = join '', keys %tails;
my %rtails;
$rtails{$_} = join ' | ', @{$tails{$_}} for keys %tails;
my $rx = join ' | ', map " $_ (?! $rtails{$_} )", keys %rtails;
$rx = qr( ^ (?: [^$set] | $rx )* $ )ix;
print $rx;

print "Correct1" if     'a12454890x'  =~ $rx;
print "Correct2" unless 'a123454890x' =~ $rx;
__END__


------------------------------

Date: 1 Nov 2006 17:48:17 -0800
From: "attn.steven.kuo@gmail.com" <attn.steven.kuo@gmail.com>
Subject: Re: regular expression consecutive numbers or letters
Message-Id: <1162432097.790027.139980@h48g2000cwc.googlegroups.com>

Mirco Wahab wrote:

(snipped)
>
>    my @wordlist = qw' 1234 abcd 1a2b c2d4 ';
>
>    my $rgx = qr/. (??{ '(?:'
>                        . chr( 1+ord($&))
>                        . chr( 2+ord($&))
>                        . chr( 3+ord($&))
>                        . ')'
>                      })/x;
>
>    for (@wordlist) { print "bad: $_\n" if /$rgx/ }
>
>
> at least for 'ascii-like' stuff, but one xould start
> from here ...
>



Neat solution.  Here's a variation:

while (<DATA>)
{
    chomp;
    if (/(\w)((??{ chr(ord($^N) + 1) })){3}/)
    {
        print "Bad $_\n";
    }
    else
    {
        print "Good $_\n";
    }
}

__DATA__
1234
abcd
1235
1a2b
c2d4
abqk
abcg
abcd
1234
1245
12456799
acghij

-- 
Regards,
Steven



------------------------------

Date: 1 Nov 2006 16:03:01 -0800
From: "jm" <needin4mation@gmail.com>
Subject: Re: Regular Expression Question Why Doesn't this Match?
Message-Id: <1162425781.730139.160940@h48g2000cwc.googlegroups.com>


Christian Winter wrote:
> jm wrote:
> > /([\w\s\.\'\-]*)
> >
> > does not match this:
> >
> >     My Fictional Co.
> >
> > But it does match
> >
> >     Product by abc company
> >
> > I don't understand why it matches the second one, but not the first.
> > Doesn't my expresionsay match anything that has a word, space, dot,
> > apostrophe, or a hyphen, one or more times?  Thefirst one has a . in it
> > and it should work.  It does work on others like:
>
> The RE above isn't closed, and I doubt that it is your
> complete expression. Give a short, working examples that
> illustrates what exactly you are trying to accomplish,
> and what goes wrong. Then people will be able to aid in
> solving your problem.
>
> Otherwise, to me the pattern seems to match just fine:
> C:\> perl
> use strict; use warnings;
> $_='My Fictional Co.';
> print 'Matches: '.$1.$/ if( /([\w\s\.\'\-]*)/ );
> ^Z
>
> Matches: My Fictional Co.
> C:\>
>
> -Chris

I forgot to put the / in my example above, but it is the complete
expression.  I am trying ot match a URL for url rewriting.  One of the
products has the format like My Fictional Co. but it won't match it.



------------------------------

Date: 1 Nov 2006 16:08:36 -0800
From: "jm" <needin4mation@gmail.com>
Subject: Re: Regular Expression Question Why Doesn't this Match?
Message-Id: <1162426116.496363.298780@f16g2000cwb.googlegroups.com>


Dr.Ruud wrote:
> jm schreef:
>
> > /([\w\s\.\'\-]*)
>
> thaT iS brokeN.
>
>
> > does not match this:
> >
> >     My Fictional Co.
>
> witH thE missinG enD-slasH addeD, it doeS:
>
> echo 'My Fictional Co.' |
>   perl -nwle '/([\w\s.\x27-]*)/ and print qq{<$1>}'
>
> This prints:
> <My Fictional Co.>
>
> --
Another URL that doesn't match has the format:

A.B.C.D.  Just won't match it.  I did forget the / in my original
question.  Sorry.



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 9918
***************************************


home help back first fref pref prev next nref lref last post