Skip to content Skip to sidebar Skip to footer

Java Regex Ability To Handle Nested Matches Separately

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' 'fractionfrac

Solution 1:

As has been said in the comments, this is not a good idea. Mathematical expressions, even simple ones, are not a regular language - they are a context-free grammar. While it is hypothetically possible to match an arbitrary math expression with modern regex engines, to attempt to parse one with them is foolhardy at best. I would recommend either rolling your own lexical analyzer or using something like ANTLR.


Post a Comment for "Java Regex Ability To Handle Nested Matches Separately"