rednebmas Posted January 7, 2011 Share Posted January 7, 2011 Examples: input: (n!/(1+n)) output: frac{n!}{1+n} input: ((n+11)!/(n-k)^(-1)) output: frac{(n+11)!}{(n-k)^(-1)} input: (9/10) output: frac{9}{10} The following regex works if there are no sub parentheses. \(([^\/\)]*)\/([^\)]*)\) The following does matching parentheses @\((([^()]++|\((?:[^()]++|(?R))+\))+)\)@ I just can not figure out how to "combine them". If you would more examples let me know. Link to comment https://forums.phpfreaks.com/topic/223709-matching-parentheses-with-division/ Share on other sites More sharing options...
sasa Posted January 7, 2011 Share Posted January 7, 2011 <?php $test = '((n+11)!/(n-k)^(-1))'; $test = explode('/', substr($test, 1, -1)); $out = 'frac{'. implode('}{', $test).'}'; echo $out; ?> Link to comment https://forums.phpfreaks.com/topic/223709-matching-parentheses-with-division/#findComment-1156426 Share on other sites More sharing options...
rednebmas Posted January 12, 2011 Author Share Posted January 12, 2011 Sorry I didn't make this clear before. The division sign will not always be the only division sign. There could be multiple signs and you don't always want to put it into frac{}{}. For example ((n+11)!/(n-k)^(-1))+(11)/(2) your code would output: frac{(n+11)!}{(n-k)^(-1))+(11)}{(2} what I would like: frac{(n+11)!}{(n-k)^(-1)}+(11)/(2) Link to comment https://forums.phpfreaks.com/topic/223709-matching-parentheses-with-division/#findComment-1158526 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.