Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

REGEX Perl.. 1

Status
Not open for further replies.

promyk

MIS
Dec 27, 2007
3
PL
I have problem..

this is my code...

#!/usr/bin/perl
print "SITE:\n";
$SITE = <STDIN>;
chomp $SITE;
print "PATH:\n";
$PATH = <STDIN>;
chomp $PATH;
print "USERID:\n";
$USERID = <STDIN>;
chomp $USERID;
#Send Request
use LWP::UserAgent;
$ua = new LWP::UserAgent;
$ua->agent("Mozilla/8.0");
$ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => "$SITE$PATH/***** :) ****");
$req->header('Accept' => 'text/html');
$res = $ua->request($req);
$con = $res->content;
if ($con =! /m[0-9a-fA-F]{32}/){
print $1;
}
else{
print ":(";
}

I need grab md5 hash from site.. i have this code

main(skins/MD5HASH_HERE/header.php)

I need grab this .. this have 32 lenght.. i try

if ($con =! /m[0-9a-fA-F]{32}/

but not work..

pls help me ;)
 
hi, i'm only looking at your pattern...try

Code:
if ($con =~ /^skins\/([0-9a-fA-F]{32})\/) {

notice the following:
- in your code the regex operator was =!, it actually is =~. the negation is !~
- the m introducing the pattern slipped into the pattern itself. in your case, it's unnecessary anyway, since you don't use any fancy regex-features
- you don't store the pattern to $1. you have to put parentheses () around the part of the pattern you want to extract.
- your pattern would match an md5-hash anywhere in the string. the caret (^) is a meta-character representing the beginning of a line/string. this way, you only match and extract hashes that come right after "skins/" at the beginning of the string. you have to escape the slash / with a backslash \ since the slash / is a meta-character also.

i hope the revised pattern works, i didn't test it. at the very least you can probably learn a thing or two from the explanations :)

greetings,
michael
 
i didn't end the pattern :) forgot the slash at the end

Code:
if ($con =~ /^skins\/([0-9a-fA-F]{32})\//) {
 
Good eyes, and nicely explained Mr. Hippo.

Star for ya,
- Miller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top