Let's say I have one regular expression A and another regular expression B as input. I want to create a new regular expression C which matches a line if and only if
- A matches the line and
- B does not match the line.
I am able to manually create C for very simple cases of A and B: Let's say A is x
and B is y
, then C = ^[^y]*x[^y]*$
would be a valid solution.
Obviously, the problem gets harder as A and B get more complex. Is there a generic algorithm for creating such a regular expression C out of A and B?
Note: Since regular languages are closed under intersection and complement, such an algorithm should theoretically exist. I am aware that the expressive power of regular expressions available in modern IT systems exceeds that of formal regular languages, but a solution where A and B are restricted to the subset of features available in formal languages, but C uses extended features of modern-day regex engines, is perfectly fine for me.