在这种情况下如何使用REGEX? [关闭]

This is my patterns :

"X+X" => Example : 10+9

"X+X+X" => Example : 8+10+9

"X+(X+X)+X" => Example : 10+(8+6)+11

This is the rules :

The last number should be always "encapsulated" between italic marker like this : "10+<i>9</i>" , "8+10+<i>9</i>"

If two "+" symbols are present, the content between two "+" should be in bold like this : "8+<b>10</b>+<i>9</i>", "10+(<b>8+6</b>)+<i>11</i>

Have you an idea ?

Try this one

echo preg_replace(array('/\((.*)\)/','/\+([0-9])+\+/','/[0-9]+$/'), array('(<b>$1</b>)','+<b>$1</b>+','<i>$0</i>'), '11+5+3');