I am using PHP and am trying to split up a string such as this:
3x^3 - 4x^2 + 2x - 3 + 5x^5 - 2x^7 between all the
- (minus) and
+ (plus) symbols. I have tried using explode(), but this can only accept one condition (only
+, not both).
I have looked at the preg_split() function, and have tried using
"/+|-/" as the regular expression for the first condition, but it does not work because
+ is not treated as the character "+", but as an operator for regex. How could I split up the string between
+ using proper regex?
UPDATE: Sahil Gulati, thank you for your response. The regular expression you posted worked perfectly. However, after reading symcbean's comment, I realized I also need to keep the signs. How would I accomplish this?