Inverting a regular expression?

The problem with trying to do this is the length to consider a
mismatch. If you wanted the mismatch to be considered up to
the next match, you could do something like this:

/(?!#{re}).*?(?=#{re}|$)/

or

/((?!#{re}).)*/

I don't see any practical application for doing something like
this. Is this just a academic question?

···

--- Harry Ohlsen <Harry_Ohlsen@hyperion.com> wrote:

A colleague of mine just asked me whether it was possible to
invert an
arbitrary regular expression. Ie, create a new regular
expression that
matches whatever the original *didn't*.

It seems like quite a difficult problem to me, but maybe I'm
just not
looking at it the right way.

Obviously simple cases are easy. Eg

   re = /[a-z]/
   inverse = /[^a-z]/

However, I think it would be much harder for arbitrary cases.
Eg, how
would one automatically invert something like the following

   /<[^<>]*id="!?(region8-).*?>/

Note that I'm not talking about finding lines that don't
contain the
pattern (a la "grep -v"); I'm talking about finding all the
occurrences
within a single line that don't match it.

Inquisitively yours,

Harry O.

************************************************************************

If you have received this e-mail in error, please delete it
and notify the sender as soon as possible. The contents of
this e-mail may be confidential and the unauthorized use,
copying, or dissemination of it and any attachments to it, is
prohibited.

Internet communications are not secure and Hyperion does not,
therefore, accept legal responsibility for the contents of
this message nor for any damage caused by viruses. The views
expressed here do not necessarily represent those of
Hyperion.

For more information about Hyperion, please visit our Web
site at www.hyperion.com

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around