Regular expressions are not the best tool for this, because you will have nested parts of your input text.
In this case it with be more robust to use a parser, but that has a bit of a learning threshold. ANTLR4 is a free parser originally for Java, but it has a version for C# as well. See
ANTLR[
^]
Note: The code is free but the book isn't, so you need to find examples online
Here is one:
Antlr 4 with C# and Visual Studio 2012 | Programming pages[
^]
That said, you could try a simpler approach, that might work.
If you first split the input string where you have AND you will get something like this:
Loan no = 12345
(Borrower First Name Contains Milena OR Buy Side Lock Date = 03/13/2016)
Last Finished Milestone = Decisioned OR Subject Property State = NC
Loan Amt > 50000
This parts will be easier to examine one by one.
If you replace the OR to an AND in the first expression, you will split the parenthesis in two parts.
Loan no = 12345
(Borrower First Name Contains Milena
Buy Side Lock Date = 03/13/2016)
Last Finished Milestone = Decisioned OR Subject Property State = NC
Loan Amt > 50000
This complicates things, but if you have a counter, you will increment when you find a ( and then decrement when you find a ), even if it is in a different part.
Maybe not the most robust of solutions, but it might be worth to give it a try before you get into a real parser.