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
/(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;
$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;
}
}
$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.
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;
}