Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

groups perl pattern matching question



3:10 pm on Aug 11, 2009 (gmt 0)

5+ Year Member


I have the code below. I also am thankful someone in this forum told me about expresso so I can build regular expressions quite easily. Unfortunately, some things don't move over to perl without issue. I saw some example code that said what I'm doing is possible in perl, but when I write it, it doesn't give me what I want. I'm just trying to get the results of the first matched group in the code below as $1 but it's not doing it. There must be a simple explanation but I can't see it.

#!/usr/bin/perl -w

my $msline ="";
my $dataline ="";
my $msnumtext ="MSNumbers=";

$msline = "<TD CLASS=\"shared\"><a href=http://www.mydomain.com/aac/index.php?Action=sm_hot&amp;MSNumbers=316030>316030</a></TD>";

if ($msline =~ /$msnumtext(\d)+/) {
print "Msline is: $msline\n";
$dataline = $1;
print "Dataline value is: $dataline \n";
print "msnumtext is: $msnumtext \n";

What I'm trying to accomplish here is simply to get the digits after the MSNumbers= so in this example it would be "316030"

Thanks in advance.


6:33 pm on Aug 11, 2009 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

it's not doing it

what result are you getting?
have you checked any of the Perl Regular Expressions resources linked in the Perl Server Side CGI Scripting forum Charter [webmasterworld.com]?


7:28 pm on Aug 11, 2009 (gmt 0)

5+ Year Member

From my previous post: "I saw some sample code..." --> not from the reference you suggested, but now, yes, here is a snippet from the reference you suggested which is basically telling me the same thing from the example I was looking at elsewhere. So I take it you are saying that my code looks good and you don't see a problem with it?

Example doing basically the same thing from the link reference you gave:
1. $x = "cat dog house"; # 3 words
2. while ($x =~ /(\w+)/g) {
3. print "Word is $1, ends at position ", pos $x, "\n";
4. }

What is the result I'm getting? Right here:

Msline is: <TD CLASS="shared"><a href=http://www.mydomain.com/aac/index.php?Action=sm_hot&amp;MSNumbers=316030>316030</a></TD>
Dataline value is: 0
msnumtext is: MSNumbers=

So...value is zero. I would think the value would be 316030

Anyone else who may know why I'm getting zero instead of 316030?


10:19 pm on Aug 11, 2009 (gmt 0)

5+ Year Member

In the first code you posted all you need do is move the + quantifier to inside the parentheses:



11:25 pm on Aug 11, 2009 (gmt 0)

5+ Year Member

No way. That was it. Thanks perl_diver. You're the man.


5:08 am on Aug 12, 2009 (gmt 0)

5+ Year Member

Yes way ;)

Featured Threads

Hot Threads This Week

Hot Threads This Month