Need regexp to parse newsgroups

M

M.L.

Hi. Using the Xref header field of newsgroup messages, I need a regexp
that will allow me to drop all newsgroups in that list containing the
word "general". I need one that works, and to find why the one I created
isn't working.

Example Xref:
Xref: prodigy.net general.soc:449517 chi.general:641065
soc.general.sci:329682 francom.chatting.generale:152591

My regexp attempt passes general.soc (good) but not soc.general (bad) or
chi.general (good):
..*[^(chi\.)(microsoft\.public\.windowsxp\.)]general.*

In short, I want the following newsgroup examples to pass the Xref
filter so they can be dropped:
general.soc
soc.general
soc.general.sci
francom.chatting.generale

I want the following two to fail so they will be retained:
chi.general
microsoft.public.windowsxp.general

Any assistance would be greatly appreciated. Thanks in advance.
 
B

brian d foy

Abigail said:
M.L. ([email protected]) wrote on VCCLXX September MCMXCIII in
{} In short, I want the following newsgroup examples to pass the Xref
{} filter so they can be dropped:
{} general.soc
{} soc.general
{} soc.general.sci
{} francom.chatting.generale
{}
{} I want the following two to fail so they will be retained:
{} chi.general
{} microsoft.public.windowsxp.general
{}
{} Any assistance would be greatly appreciated. Thanks in advance.


@groups = grep {$_ eq 'chi.general' ||
$_ eq 'microsoft.public.windowsxp.general' ||
!/general/} @groups;


As Abigail does, forget about the exceptions in the regex. Pass those
through first then look at the rest. Note that I added \b to regex so
you don't filter out alt.generalissimo.franco. :)

#!/usr/bin/perl

my $string = "prodigy.net general.soc:449517 chi.general:641065
soc.general.sci:329682 francom.chatting.generale:152591";

%Exceptions = map { $_, 1 } qw( chi.general
microsoft.public.windowsxp.general );

print
join " ",
grep {
my( $group, $number ) = split /:/;
exists $Exceptions{$group} or $group !~ /\bgenerale?\b/
}
split /\s+/, $string;
 
M

M.L.

{} In short, I want the following newsgroup examples to pass the
As Abigail does, forget about the exceptions in the regex. Pass those
through first then look at the rest. Note that I added \b to regex so
you don't filter out alt.generalissimo.franco. :)

#!/usr/bin/perl

my $string = "prodigy.net general.soc:449517 chi.general:641065
soc.general.sci:329682 francom.chatting.generale:152591";

%Exceptions = map { $_, 1 } qw( chi.general
microsoft.public.windowsxp.general );

print
join " ",
grep {
my( $group, $number ) = split /:/;
exists $Exceptions{$group} or $group !~ /\bgenerale?\b/
}
split /\s+/, $string;

Sorry to be replying so late. Thanks for the advice, I'll try to follow
what I can. I need to mention that the regexp is not going to be used
within a Perl script. It's just an entry to a Windows program that uses
Perl regexps for filtering. So grep and map are out. I'll check to see
if Abigail's will work though. Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top