I have got a program that takes user input in a form of logical expression (for example: (p=>(r||q)) ) and it divides the string in to substrings which are defined by brackets. I am using pattern and matcher.
So, for example user inputs:
((p||q)=>r).
I want to get 2 substrings which are:
p||q
and
(p||q)=>r.
However I am only getting this:
(p||q
Here is the code that I am using
Scanner scanner = new Scanner(System.in);
System.out.println("Enter formula: ");
String formula = scanner.next();
Pattern pattern = Pattern.compile("\\((.*?)\\)");
Matcher matcher = pattern.matcher(formula);
while(matcher.find())
{
String s = matcher.group(1);
System.out.println(s);
}
So I need a way that the program finds all the substrings in that string.