I am facing difficulty in splitting the input string into an array:
'((Application = smtp AND "Server Port" != 25) AND (Application = smtp AND "Server Port" != 25)) OR (Application = pop3 AND "Server Port" != 110) OR (Application = imap AND "Server Port" != 143) AND (Application = imap OR "Server Port" != 143)'.split(/\(([^)]+)\)/g)
Result obtained:
["", "(Application = smtp AND "Server Port" != 25", " AND ", "Application = smtp AND "Server Port" != 25", ") OR ", "Application = pop3 AND "Server Port" != 110", " OR ", "Application = imap AND "Server Port" != 143", " AND ", "Application = imap OR "Server Port" != 143", ""]
Desired result:
["", "(Application = smtp AND "Server Port" != 25) AND (Application = smtp AND "Server Port" != 25")", OR ", "Application = pop3 AND "Server Port" != 110", " OR ", "Application = imap AND "Server Port" != 143", " AND ", "Application = imap OR "Server Port" != 143", ""]
Note the content of the 1st index
"(Application = smtp AND "Server Port" != 25) AND (Application = smtp AND "Server Port" != 25")"
Any suggestions for achieving this using RegEx?
EDIT Formatted version:
The input string I have is as follows:
(
(
(App = smtp AND "Server Port" != 25)
OR
(App = pop3 AND "Server Port" == 20)
)
AND
(App = smtp AND "Server Port" != 35)
)
OR
(App = pop3 AND "Server Port" != 110)
AND
(
(App = imap AND "Server Port" != 143)
OR
(App = pop3 AND "Server Port" == 20)
)
AND (App = imap OR "Server Port" != 143)
Transformation needed:
[
[
[
'App = smtp AND "Server Port" != 25',
'OR',
'App = pop3 AND "Server Port" == 20'
],
'AND',
'App = smtp AND "Server Port" != 35'
],
'OR',
'App = pop3 AND "Server Port" != 110',
'AND',
[
[
'App = imap AND "Server Port" != 143',
'OR',
'App = pop3 AND "Server Port" == 20'
]
],
'AND',
'App = imap OR "Server Port" != 143'
]