Inverting a regular expression?

Harry,

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*.

    As many people have said, it is not really possible in the general
case to convert an arbitrary extended regular expression into another
regular expression that matches anything the first one does not.

I'm talking about finding all the occurrences within a single
line that don't match it.

    However, this part can be achieved in Ruby:

irb(main):001:0> "abcabcabbabbcabccabbabc".scan(/bc/)
=> ["bc", "bc", "bc", "bc", "bc"]
irb(main):002:0> "abcabcabbabbcabccabbabc".split(/bc/)
=> ["a", "a", "abbab", "a", "cabba"]

    I realize this probably isn't exactly what you're looking for, but
it's close enough to be worth mentioning.

    - Warren Brown