Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Quantifier...bigger than 32766...in regex

Reply
Thread Tools

Quantifier...bigger than 32766...in regex

 
 
leegee@gmail.com
Guest
Posts: n/a
 
      05-04-2006
Please help. When I say:

qr/^.{1,$Radio::AudioNotes::COL_SIZE->{TEXT}}$/m, ],

Perl says:

Quantifier in {,} bigger than 32766 before HERE mark in regex m/^.{
<< HERE 1,65535}$/

It appears from the archives of this gruop that this is unavoidable -
does anyone know otherwise?

Or can anyone think of a work-around that would fit the above?

I'm trying to limit an input string to a specific length, that of a
MySQL MEDIUMTEXT column.

Thanks in anticipation,
lee

 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      05-04-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote in news:1146742722.221433.143330
@y43g2000cwc.googlegroups.com:

> Please help. When I say:
>
> qr/^.{1,$Radio::AudioNotes::COL_SIZE->{TEXT}}$/m, ],

....

> I'm trying to limit an input string to a specific length, that of a
> MySQL MEDIUMTEXT column.


Yeeehaaaw! I think I spotted another SAQ:

See

perldoc -f length

Sinan

--
A. Sinan Unur <(E-Mail Removed)>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc...uidelines.html

 
Reply With Quote
 
 
 
 
leegee@gmail.com
Guest
Posts: n/a
 
      05-04-2006
I'd be grateful to hear an answer better than this (please!):

use strict;

my %COL_SIZE = (
aTINYTEXT => 255, # 8-bit
bTEXT => 65535, # 16-bit
cMEDIUMTEXT => 16777215, # 32-bit
dLONGTEXT => 4294967295, # 64-bit
);

foreach (sort keys %COL_SIZE){
print $_
."\n\t".
($COL_SIZE{$_} / 32766)
."\n\t".
int ($COL_SIZE{$_} / 32766)
."\n\t".
($COL_SIZE{$_} % 32766)
."\n\n".
'qr['.
(
'.{1,32766}' x int ($COL_SIZE{$_} / 32766)
)
.'.{1,'.($COL_SIZE{$_} % 32766).'}'
.']'
."\n\n\n"
}

__END__

Outputs:

aTINYTEXT
0.00778245742537997
0
255

qr[.{1,255}]


bTEXT
2.00009155832265
2
3

qr[.{1,32766}.{1,32766}.{1,3}]

[...etc]

 
Reply With Quote
 
David Squire
Guest
Posts: n/a
 
      05-04-2006
(E-Mail Removed) wrote:
> I'd be grateful to hear an answer better than this (please!):


Than what? Please quote context when replying (see the posting
guidelines that are posted here frequently)

DS
 
Reply With Quote
 
LeeGee
Guest
Posts: n/a
 
      05-04-2006
Problem as posted at top of thread: when I say:

qr/^.{1,$Radio::AudioNotes::COL_SIZE->{TEXT}}$/m, ],

Perl says:

Quantifier in {,} bigger than 32766 before HERE mark in regex m/^.{

<< HERE 1,65535}$/

(Described in perldoc prelre)

Best solution so far, but I would appreciate a "nicer" one:

use strict;

$|=0;
my %COL_SIZE = (
bTINYTEXT => 255, # 8-bit
cTEXT => 65535, # 16-bit
dMEDIUMTEXT => 16777215, # 32-bit
# eLONGTEXT => 4294967295, # 64-bit
);

foreach (sort keys %COL_SIZE){
my $s = '^';
$s .= '(.{0,32766}){0,' . int($COL_SIZE{$_} / 32766) .'}' if
int($COL_SIZE{$_} / 32766);
$s .= '.{0,'.($COL_SIZE{$_} % 32766).'}' if ($COL_SIZE{$_} % 32766);
$s .= '$';

my $qr = qr[$s]m;
die ref $qr if ref $qr ne 'Regexp';

print $qr."\n";
for my $i ( reverse sort values %COL_SIZE ){
my $t = 'x' x $i;
print "\tSrting with length $i ";
if ($t !~ $qr){
print "FAILS regex\n"
} else {
print "PASSES regex\n";
}

}
print "\n\n";
}

__END__

Outputs:

(?m-xis:^.{0,255}$)
Srting with length 65535 FAILS regex
Srting with length 255 PASSES regex
Srting with length 16777215 FAILS regex


(?m-xis:^(.{0,32766}){0,2}.{0,3}$)
Srting with length 65535 PASSES regex
Srting with length 255 PASSES regex
Srting with length 16777215 FAILS regex


(?m-xis:^(.{0,32766}){0,512}.{0,1023}$)
Srting with length 65535 PASSES regex
Srting with length 255 PASSES regex
Srting with length 16777215 PASSES regex



Tool completed successfully

 
Reply With Quote
 
LeeGee
Guest
Posts: n/a
 
      05-04-2006
> > (E-Mail Removed) wrote in news:(E-Mail Removed) oups.com:
> >
> > Please help. When I say:
> > qr/^.{1,$Radio::AudioNotes::COL_SIZE->{TEXT}}$/m, ],

> ...
> > I'm trying to limit an input string to a specific length, that of a
> > MySQL MEDIUMTEXT column.

>
> Yeeehaaaw! I think I spotted another SAQ:
>
> See
> perldoc -f length


Sorry, Sinan - I forgot to say that I *must* use a regular expression.
For my own perverse reasons. But thanks for taking the time to be
helpful.

Lee

 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      05-04-2006
(E-Mail Removed) schreef:
> Please help. When I say:
>
> qr/^.{1,$Radio::AudioNotes::COL_SIZE->{TEXT}}$/m, ],
>
> Perl says:
>
> Quantifier in {,} bigger than 32766 before HERE mark in regex
> m/^.{ << HERE 1,65535}$/


Generate is as
/^.{1,32766}.{0,32766}.{0,3}$/


#!/usr/bin/perl
use strict;
use warnings;

use constant RE_qmax => 32766;

my $n = 65536; # $Radio::AudioNotes::COL_SIZE->{TEXT} ;

my $re = q</^.{1,> ;

while ($n > RE_qmax)
{
$re .= RE_qmax . q<}.{0,>;
$n -= RE_qmax;
}
$re = qr<$re$n}\$/>;

print "$re\n";

--
Affijn, Ruud

"Gewoon is een tijger."


 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      05-04-2006
Dr.Ruud schreef:
> (E-Mail Removed) schreef:


>> When I say:
>>
>> qr/^.{1,$Radio::AudioNotes::COL_SIZE->{TEXT}}$/m, ],
>>
>> Perl says:
>>
>> Quantifier in {,} bigger than 32766 before HERE mark in regex
>> m/^.{ << HERE 1,65535}$/

>
> Generate is as
> /^.{1,32766}.{0,32766}.{0,3}$/


Corrected code:

#!/usr/bin/perl
use strict;
use warnings;

use constant RE_qmax => 32766;

my $n = $Radio::AudioNotes::COL_SIZE->{TEXT} ;
my $re = q<^.{1,> ;

while ($n > RE_qmax)
{
$re .= RE_qmax . q<}.{0,>;
$n -= RE_qmax;
}
$re = qr<$re$n}$>;

print "$re\n";

--
Affijn, Ruud

"Gewoon is een tijger."


 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      05-04-2006
LeeGee <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> Problem as posted at top of thread: when I say:
>
> qr/^.{1,$Radio::AudioNotes::COL_SIZE->{TEXT}}$/m, ],
>
> Perl says:
>
> Quantifier in {,} bigger than 32766 before HERE mark in regex m/^.{
>
> << HERE 1,65535}$/
>
> (Described in perldoc prelre)
>
> Best solution so far, but I would appreciate a "nicer" one:


[snip]

How about

# construct a regex that matches up to $n characters without using
# a quantifier > MAX
use constant MAX => 32766;
sub mk_re {
my $n = shift;
my $q = int $n/MAX;
die "Size $n too large" if $q > MAX; # $n > MAX**2
sprintf
'^(??:.{%d}){0,%d}.{0,%d}|(?:.{%d}){%d}.{0,%d})$ ',
MAX, $q-1, MAX, MAX, $q, $n % MAX;
}

This works up to a size of MAX**2. The regex matches an empty string,
which is not quite to specification. That can be repaired in various
ways. If you want to return the ready-made qr/.../, you can use

return qr/$_/ for sprintf ...;


Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
 
Reply With Quote
 
Brian McCauley
Guest
Posts: n/a
 
      05-04-2006
LeeGee wrote:

> (?m-xis:^(.{0,32766}){0,512}.{0,1023}$)
> Srting with length 65535 PASSES regex
> Srting with length 255 PASSES regex
> Srting with length 16777215 PASSES regex


String with length 16777217 would fail but probably not before the end
of the universe.

Looking at some much smaller numbers and counting the number of times
the RE engine backtracks you may start to see the problem...

local our $count;
('x' x 2000 ) =~ /(?m-xis:^(.{0,9}){0,4}(?{ $count++ })$)/;
print $count;

Prints 8201.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How make regex that means "contains regex#1 but NOT regex#2" ?? seberino@spawar.navy.mil Python 3 07-01-2008 03:06 PM
regex problem: 'greater than' 'less than' and 'equals' not matching! falcon Java 10 02-24-2006 01:23 PM
Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine? =?Utf-8?B?SmViQnVzaGVsbA==?= ASP .Net 2 10-22-2005 02:43 PM
Java regex imposture re: Perl regex compatibility a_c_Attlee@yahoo.com Java 2 05-06-2005 12:16 AM
perl regex to java regex Rick Venter Java 5 11-06-2003 10:55 AM



Advertisments