Jump to content

Matching Parentheses with Division


rednebmas

Recommended Posts

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

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)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.