simplifying AND OR Boolean Expression [closed]

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)