Re: [voxtech] Help with regular expressions needed.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [voxtech] Help with regular expressions needed.
Everbody wrote lots of sh*t:
My 2 cents on the banter.
This really isn't a difficult problem. (Now I hope I'm right as I don't
use kmail;
if not I'm certainly going to look the fool) :)
I have worked up a quick expression checker in perl:
A data file:

one Capitals in a row in one place
two CApitals in a row in one place
three CAPitals in a row in one place
four CAPItals in a row in one place
One Capitals in a row in Two places
TWo Capitals in a row in TWo places
THRee Capitals in a row in TWO places
FOUR CAPItals in a row in Two places
One Capitals in a row in Three places
TWo CApitals in a row in THree places
THRee CAPitals in a row in THRee places
FOUR CAPItals in a row in THREe places

A perl program:

#!/usr/bin/perl w
#
# An example script to check for patterns of capital letters in perl.
#
while(<>)
{
chomp();
# NO lower case letters
if( /^.*[az]+.*$/ )
# 2 capitals in a row
# if(! /^.*[AZ]{2,}.*$/ )
# 3 capitals in a row
# if(! /^.*[AZ]{3,}.*$/ )
# 4 capitals in a row
# if(! /^.*[AZ]{4,}.*$/ )
# At least 2 caps in a row in at least two places
# if(! /^.*[AZ]{2,}.+[AZ]{2,}.*$/ )
# At least 3 caps in a row in at least two places
# if(! /^.*[AZ]{3,}.+[AZ]{3,}.*$/ )
# At least 4 caps in a row in at least two places
# if(! /^.*[AZ]{4,}.+[AZ]{4,}.*$/ )
# At least 2 caps in a row in at least three places
# if(! /^.*[AZ]{2,}.+[AZ]{2,}.+[AZ]{2,}.*$/ )
# At least 3 caps in a row in at least three places
# if(! /^.*[AZ]{3,}.+[AZ]{3,}.+[AZ]{3,}.*$/ )
# At least 4 caps in a row in at least three places
if(! /^.*[AZ]{4,}.+[AZ]{4,}.+[AZ]{4,}.*$/ )
{
print "Good: $_\n";
}
else
{
print "Bad: $_\n";
}
}

A sample run for the rule in question: (the first one)

tres@ares:~/program/quick$ ./regexp1.pl regexp1.dat
Good: one Capitals in a row in one place
Good: two CApitals in a row in one place
Good: three CAPitals in a row in one place
Good: four CAPItals in a row in one place
Bad:
Good: One Capitals in a row in Two places
Good: TWo Capitals in a row in TWo places
Good: THRee Capitals in a row in TWO places
Good: FOUR CAPItals in a row in Two places
Bad:
Good: One Capitals in a row in Three places
Good: TWo CApitals in a row in THree places
Good: THRee CAPitals in a row in THRee places
Good: FOUR CAPItals in a row in THREe places
Bad:
Bad: NO LOWER CASE AT ALL
tres@ares:~/program/quick$

A sample run (for the last rule):

tres@ares:~/program/quick$ ./regexp1.pl regexp1.dat
Good: one Capitals in a row in one place
Good: two CApitals in a row in one place
Good: three CAPitals in a row in one place
Good: four CAPItals in a row in one place
Good:
Good: One Capitals in a row in Two places
Good: TWo Capitals in a row in TWo places
Good: THRee Capitals in a row in TWO places
Good: FOUR CAPItals in a row in Two places
Good:
Good: One Capitals in a row in Three places
Good: TWo CApitals in a row in THree places
Good: THRee CAPitals in a row in THRee places
Bad: FOUR CAPItals in a row in THREe places
tres@ares:~/program/quick$

A Line disected:
if(! /^.*[AZ]{4,}.+[AZ]{2,}.+[AZ]{4,}.*$/ )
This line looks for at least 4 capital letters in a row at least
3 times in a line by doing:
Find the beginning of the line
Find at least 0 occurances of any character
Find at least 4 cap in a row
Find at least 1 occurance of any character
Find at least 4 caps in a row
Find at least 1 occurance of any character
Find at least 4 caps in a row
Find at least 0 occurances of any character
Find the end of the line
Then report success/failure.
As you can see This will fail for the case of a blank subject or in the
case that Micah brought
up. Some of the following rules can handle some more elaborate cases.
The next challenge is to change the step of repeating
[AZ]{4,}.+
to account for multiple occurances.
This was supposed to take 10 minutes, 40 for the prog, testing, and
email isn't too bad though.
Cheers,
Tres
