Welcome to WebmasterWorld Guest from 54.242.9.97

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)

New User

5+ Year Member

joined:May 13, 2009
posts: 21
votes: 0


Hi:

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)

Administrator

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

joined:Aug 10, 2004
posts:10562
votes: 14


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)

New User

5+ Year Member

joined:May 13, 2009
posts: 21
votes: 0


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)

Preferred Member

10+ Year Member

joined:Jan 5, 2006
posts:536
votes: 0


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

(\d+)

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

New User

5+ Year Member

joined:May 13, 2009
posts: 21
votes: 0


No way. That was it. Thanks perl_diver. You're the man.
5:08 am on Aug 12, 2009 (gmt 0)

Preferred Member

10+ Year Member

joined:Jan 5, 2006
posts:536
votes: 0


Yes way ;)
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members