develooper Front page | perl.beginners | Postings from March 2023

A Regular Expression Problem in Perl 5.28

Thread Next
From:
Martin McCormick
Date:
March 28, 2023 20:17
Subject:
A Regular Expression Problem in Perl 5.28
Message ID:
E1phFkh-0004d8-Pi@wb5agz.lan
I've been fighting this for several days and it is a very simple
regular expression problem that should be easy enough for a
second grader but I can't seem to get it to work.

	The string I am interested in testing for starts with 5
or 6 digits in a row and all I need to do is determine that the
first 5 or 6 characters are numbers Period.  That's all.

	For some reason, it has never passed the test.

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

use warnings::unused;
use File::Copy;

#main local variables
my $workname  = '106787pdtb';
my $regextest = '/^\d+\{5,\}/';
if ( $workname =~ $regextest ) { print "yes\n"; }

$workname contains the data I am testing.  $regextest is the test
for the first 6 characters.

	I was able to do this the hard way and test with 6 \d's
as in

my $regextest = '\d\d\d\d\d\d';
if ($workname =~ $regextest) {print "yes\n"; }

I got a yes that time but that's not good enough.

I'll probably kick myself when I find out what I am missing, but
I can't seem to get this to work.

	Thank you.

Martin McCormick

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About