I have this logic programming software that can output results in a text file in the following form:
[-a(b), +i(c), +i(d)]
[-a(f(g(a))), -a(f(a,b)), -a(f(c)), -a(f(d)), -a(b)]
...
Which can extend to hundreds or thousands of lines.
I just want to be able to narrow this number by removing lines that contains parenthesis inside parenthesis (in other terms, functions inside predicates) like -a(f(g(a))) and -a(f(c))… And keep all the other lines.
Can anybody guide me and perhaps provide me a simple example on how to achieve this in the simplest manner, nothing fancy at all, maybe in a VBScript or a Batch (Yes I am on windows), that reads the content of the text file and removes the unappropriated lines.
Edit: vbs working sample
Dim re, targetString
Set re = New RegExp
With re
.Pattern = "\([^()]*\("
.Global = False
.IgnoreCase = False
End With
targetString = "[-a(f(g(a))), -a(f(a,b)), -a(f(c)), -a(f(d)), -a(b)]"
if re.Test(targetString) <> True Then
MsgBox "valid",0,"test"
else
MsgBox "invalid",0,"test"
end if
Matching nested parentheses is always a tricky business for regexes since recursive structures are not regular. But in your examples, you could simply look for lines where two opening parentheses follow each other without an intervening closing parenthesis:
Explanation: