I am trying to split a string like this:
x^-5 - 3
into a list like this:
[x^-5, -, 3]
The first minus after the ^ must be at the same list index as the x, because it's just the negative exponent. However, I want other minuses, which are not an exponent of anything, to be on their own index.
When splitting by -, obviously my x^-5 gets split into two as well.
So is there any way I can achieve this using RegEx or something like that?
Thanks in advance
If you use allMatches instead of split, you can use a pattern like this:
(?:\^\s*-|[^\-])+|-
Working example: DartPad
-, or ^-.- that is not an exponent, we match it alone, similar to a split.Some notes:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With