How can I create a regexp which do that?

J

jfbarro

Hi!

I am a completly newbie to regexp and I would like to find a regular
expression which execute the following search:
"Show me all *Exception* since they are different from EOFException and
SocketException"

I tried [^EOF]Exception&[^Socket]Exception, but it didn't function like
I expected.

Does anyone have any clue?

Thanks in advance
 
J

Josef Moellers

Hi!

I am a completly newbie to regexp and I would like to find a regular
expression which execute the following search:
"Show me all *Exception* since they are different from EOFException and
SocketException"

I tried [^EOF]Exception&[^Socket]Exception, but it didn't function like
I expected.

The angular brackets ([]) describe character classes, you can view them
as character _sets_, not strings, so your pattern would match anything
that had "Exception" *not* being precedded by either E, O, or F (that
would exclude "EOFException"!). Same applies for the other character class.

If you want to match "Exception" as a free standing word, have a look
(perldoc perlre) at the word boundary meta character '\w'.

HTH,
 
A

A. Sinan Unur

(e-mail address removed) wrote in
I am a completly newbie to regexp and I would like to find a regular
expression which execute the following search:
"Show me all *Exception* since they are different from EOFException
and SocketException"

I tried [^EOF]Exception&[^Socket]Exception, but it didn't function
like I expected.

Does anyone have any clue?

You might be able to do something with look-behind assertions, but I
would just spell it out:

#!/usr/bin/perl

use strict;
use warnings;

my %ignore = (
EOFException => 1,
SocketException => 1,
);

my $text = <<TEXT;
EOFException Exception SocketException IOException
ParseException BzztException and more exceptions
TEXT

while ( $text =~ m{ \b(\w+Exception)\b }gx ) {
my $exception = $1;
unless ( $ignore{$exception} ) {
print "$exception\n";
}
}

Sinan
 
T

Tassilo v. Parseval

Also sprach Josef Moellers:
Hi!

I am a completly newbie to regexp and I would like to find a regular
expression which execute the following search:
"Show me all *Exception* since they are different from EOFException and
SocketException"

I tried [^EOF]Exception&[^Socket]Exception, but it didn't function like
I expected.

The angular brackets ([]) describe character classes, you can view them
as character _sets_, not strings, so your pattern would match anything
that had "Exception" *not* being precedded by either E, O, or F (that
would exclude "EOFException"!). Same applies for the other character class.

If you want to match "Exception" as a free standing word, have a look
(perldoc perlre) at the word boundary meta character '\w'.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ITYM '\b'.

Tassilo
 
J

Josef Moellers

Tassilo said:
Also sprach Josef Moellers:

Hi!

I am a completly newbie to regexp and I would like to find a regular
expression which execute the following search:
"Show me all *Exception* since they are different from EOFException and
SocketException"

I tried [^EOF]Exception&[^Socket]Exception, but it didn't function like
I expected.

The angular brackets ([]) describe character classes, you can view them
as character _sets_, not strings, so your pattern would match anything
that had "Exception" *not* being precedded by either E, O, or F (that
would exclude "EOFException"!). Same applies for the other character class.

If you want to match "Exception" as a free standing word, have a look
(perldoc perlre) at the word boundary meta character '\w'.

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ITYM '\b'.

Sorry, yes. That should teach me not to write responses between two
important tasks which both keep me occupied.
 

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,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top