homepage Welcome to WebmasterWorld Guest from 50.17.27.205
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Ignoring certain regex matches
lindajames




msg:444812
 6:09 pm on Jan 28, 2004 (gmt 0)

Hi,

I have the following code that checks to see if the word error (not case sensative) exists and if so it displays an error message if not then it continues with executing the rest of script

if ($response->is_success && $Content!~ /error/i) {
return $response->content;
}
else {
$Error_msg = $response->message;
return undef;
}
}

the problem is that on the page that it looks at there is always a fixed word there called "Error Pages" so i wanted the above code to do exactly what it does but ignore the exact word "Error Pages"

can anyone help me with this?

Cheers
Linda

 

sugarkane




msg:444813
 7:32 pm on Jan 28, 2004 (gmt 0)

Change your regex to:

/(error.*?){2,}/gi

and it should work.

Another way is a bit more of a kludge, but may be useful in a wider context (eg you don't know how many times 'Error Pages' appears in the document, but wanted to ignore them all) would be to do a regex substitution on 'Error Pages' before and after the test so that it no longer matches, eg:

$content=~s/Error Pages/Er1234567ror Pages/g;
# Do your test here
$content=~s/Er1234567ror Pages/Error Pages/g;

lindajames




msg:444814
 9:09 pm on Jan 30, 2004 (gmt 0)

sugarkane mentioned that i can use the following:

$content=~s/Error Pages/Er1234567ror Pages/g;
if ($response->is_success && $Content!~ /error/i) {
$content=~s/Er1234567ror Pages/Error Pages/g;
# carry on with whatever you're doing if 'error' is found
}
else {
$content=~s/Er1234567ror Pages/Error Pages/g;
# carry on with whatever you're doing if 'error' is NOT found
}

but the problem is i cannot get it to work with my code. my code looks as follows, can anyone please help me get the above code to work with the code below where it reads if ($response->is_success && :

my $request = GET $query_string;

$request->authorization_basic($User_name, $Password);

my $response = $ua->request($request);
$Content = $response->content;

if ($response->is_success && $Content!~ /error (?!pages)/i) {
return $response->content;
}
else {
$Error_msg = $response->message;
return undef;
}
}

sugarkane




msg:444815
 12:28 am on Feb 1, 2004 (gmt 0)

my $request = GET $query_string;

$request->authorization_basic($User_name, $Password);

my $response = $ua->request($request);
$Content = $response->content;

$content=~s/Error Pages/Er1234567ror Pages/g;
if ($response->is_success && $Content!~ /error/i) {
$content=~s/Er1234567ror Pages/Error Pages/g;
return $response->content;
}
else {
$Error_msg = $response->message;
return undef;
}
}

As I mentioned earlier it's a bit of a kludge, but should hopefully sort out the problem in your particular case.

lindajames




msg:444816
 12:52 am on Feb 1, 2004 (gmt 0)

thanx, i'll try it out

dkubb




msg:444817
 4:07 am on Feb 1, 2004 (gmt 0)

The following should work without any kludges. It uses a negative look-ahead assertion to look for the exact word "error" that is not followed by the word "pages".

Also note that some of the other examples in this thread would mistakenly match words that have error as a substring, like "terror" or "errors". You can account for this by using \b to match the word boundaries.

if($response->is_success and $response->content !~ /\berror\b(?!\s+pages)/i) {
return $response->content;
}
else {
$Error_msg = $response->message;
return undef;
}

lindajames




msg:444818
 8:52 pm on Feb 1, 2004 (gmt 0)

thanx dkubb,

it worked. can you explain what exactly the line below does:

if($response->is_success and $response->content!~ /\berror\b(?!\s+pages)/i) {

cheers

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved