I completely can't figure out how to write pattern, to achieve nested fractions in latex with my regex.
Here is couple sample user inputs:
"fractionx+3over5moveout+2"
"fractionfractionx+1over7moveoutover3moveout+1",
"fractionfractionfractionx+3over3moveoutoverx+2moveoutover7moveout+1".
Here's my regex code(I made partial versions):
\\Final version with closing "moveout" phrase
regexPattern = Pattern.compile(fraction(?<upper>.*?)over(?<lower>.*?)moveout);
regexMatcher = regexPattern.matcher(userInput);
mathFormulaInLaTeX = regexMatcher.replaceAll(\\frac{${upper}} {${lower}});
\\Starting version without "over" keyword
regexPattern = Pattern.compile(fraction(?<upper>.*));
regexMatcher = regexPattern.matcher(userInput);
mathFormulaInLaTeX = regexMatcher.replaceAll(\\frac{${upper}} {});
With the following inputs I get results:
Input: "fractionx+3over5moveout+2"
(The final regex version works fine with only one fraction)
Input: "fractionfractionx+1"
(Starting version without "over" keyword with nested fractions not working properly)
Input: "fractionfractionx+1over7moveoutover3moveout+1"
(The final regex version with nested fractions adds moveout word)
Input: "fractionfractionfractionx+3over3moveoutoverx+2moveoutover7moveout+1"
(Completly misclassified)
Is there a neat pattern solution for any number of nested fractions, to get rid of "moveout" word displaying and make nested fraction like this:
I appreciate any help.