regex empty strimg exptession

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
nanu
Forum Newbie
Posts: 2
Joined: Tue Mar 10, 2009 7:34 am

regex empty strimg exptession

Post by nanu »

Hi!

Two questions:

1. I need to find an empty string and a string that beins with anything but not HTTP.

2. What is the logical AND operator?

TIA

Nanu
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: regex empty strimg exptession

Post by prometheuzz »

1. Why regex? The things you want can be easily done with string functions.
2. There is no logical AND in regex*.

* Except in character classes, but that is probably not what you meant.
nanu
Forum Newbie
Posts: 2
Joined: Tue Mar 10, 2009 7:34 am

Re: regex empty strimg exptession

Post by nanu »

Hi!

I need regex to prevent Apache\Linux to add "corrupted" records to the access_log file.

I'm using a Suse 10 sp1 WEB server.

Following are examples of the records in the access_lo file:

192.168.254.254 - - [06/Mar/2009:11:10:22 +0200] "GET /req.png HTTP/1.0" 200 5373 "http://www.kalmanovitz.co.il/Analog_Report.html" "Mozilla/5.0 (Windows; U; Windows NT 5.1; he; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7"
::1 - - [06/Mar/2009:11:10:32 +0200] "GET /" 400 991
::1 - - [06/Mar/2009:11:10:33 +0200] "GET /" 400 991
::1 - - [06/Mar/2009:11:10:34 +0200] "GET /" 400 991
::1 - - [06/Mar/2009:11:10:35 +0200] "GET /" 400 991
::1 - - [06/Mar/2009:11:10:36 +0200] "GET /" 400 991
::1 - - [06/Mar/2009:11:10:37 +0200] "GET /" 400 991
::1 - - [06/Mar/2009:11:10:38 +0200] "GET /" 400 991
192.168.254.254 - - [06/Mar/2009:11:10:44 +0200] "GET /k_comm/Israel/English/Maps/Cities/Tel-Aviv-Yaffa/Old_Jaffa/pages/Yaffa_0095_jpg.htm HTTP/1.0" 200 505 "http://www.kalmanovitz.co.il/Analog_Report.html" "Mozilla/5.0 (Windows; U; Windows NT 5.1; he; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7"

I wish to prevent the following records from beeing added:
::1 - - [06/Mar/2009:11:10:32 +0200] "GET /" 400 991
::1 - - [06/Mar/2009:11:10:33 +0200] "GET /" 400 991


I was told to define a <SetEnvIf Request_Protocol "" dontlog> command, but it seems that "" is not the correct regex for empty string or null string.

Between the "" I need a regex for the empty\null string or everything that does not begin with HTTP.

TIA

Nanu
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: regex empty strimg exptession

Post by prometheuzz »

nanu wrote:Hi!

I need regex to prevent Apache\Linux to add "corrupted" records to the access_log file.

I'm using a Suse 10 sp1 WEB server.

Following are examples of the records in the access_lo file:

192.168.254.254 - - [06/Mar/2009:11:10:22 +0200] "GET /req.png HTTP/1.0" 200 5373 "http://www.kalmanovitz.co.il/Analog_Report.html" "Mozilla/5.0 (Windows; U; Windows NT 5.1; he; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7"
::1 - - [06/Mar/2009:11:10:32 +0200] "GET /" 400 991
::1 - - [06/Mar/2009:11:10:33 +0200] "GET /" 400 991
::1 - - [06/Mar/2009:11:10:34 +0200] "GET /" 400 991
::1 - - [06/Mar/2009:11:10:35 +0200] "GET /" 400 991
::1 - - [06/Mar/2009:11:10:36 +0200] "GET /" 400 991
::1 - - [06/Mar/2009:11:10:37 +0200] "GET /" 400 991
::1 - - [06/Mar/2009:11:10:38 +0200] "GET /" 400 991
192.168.254.254 - - [06/Mar/2009:11:10:44 +0200] "GET /k_comm/Israel/English/Maps/Cities/Tel-Aviv-Yaffa/Old_Jaffa/pages/Yaffa_0095_jpg.htm HTTP/1.0" 200 505 "http://www.kalmanovitz.co.il/Analog_Report.html" "Mozilla/5.0 (Windows; U; Windows NT 5.1; he; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7"

I wish to prevent the following records from beeing added:
::1 - - [06/Mar/2009:11:10:32 +0200] "GET /" 400 991
::1 - - [06/Mar/2009:11:10:33 +0200] "GET /" 400 991


I was told to define a <SetEnvIf Request_Protocol "" dontlog> command, but it seems that "" is not the correct regex for empty string or null string.

Between the "" I need a regex for the empty\null string or everything that does not begin with HTTP.

TIA

Nanu
The pattern "" does match an empty string in a PCRE compatible regex engine. You could also try to use the following pattern: "^\s*$" or just "\s*".

Good luck.
Post Reply