simplifying AND OR Boolean Expression

My problem is turning a string that looks like this.

"a OR (b AND c)"
into
  a OR bc

if the expression is like

"a AND (b OR c)"

 then gives

  ab OR ac

I can't able to design a correct set of loops using REGEX matching. The crux of the issue is that the code has to be completely general because I cannot assume how long the string pattern will be , nor exact places of OR AND in pattern will be.

If i input like below ,it will solve this type of expression also.

security OR ((internet OR online OR paperless) AND (bank*)) AND (mobile OR cell OR phone OR access) OR easy OR online WITHIN bank OR transaction OR mumbai OR delhi NEAR/10 agar OR (online OR internet) AND (bank) OR not OR (apple) EXCLUDE (mongo)

Topic tokenization regex parsing python

Category Data Science

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.