I have a list of expressions (containing symbols) separated by hyphens:
"exp_1-exp_2-exp_3-exp_4-..........."
I can use the regex matcher /([^-]*)-/
and the standard matcher.find()
in java to extract the expressions into
- exp_1
- exp_2
- exp_3
- exp_4
and so on.
However, I also want a list of exceptions that should be matched as a whole. For example, I want to have "a_1-b_2" and "c_3-d_4" not to split.
So, if the expression is
"exp_0-a_1-b_2-c_3-d_4-exp_5..."
the matcher should give me the list
- exp_0
- a_1-b_2
- c_3-d_4
- exp_5
How should I modify my regex expression? Or are there better alternatives?
Edit:
A typical example:
exp can be \pi_1*b_3
or \sqrt{b_2/b_4}
. I assume no minus signs (hyphens) involved. But I want to group terms for example:
String exception ="\sqrt{3}-\sqrt{2}"
So for example, the list may be
"5a^3-\sqrt{3}-\sqrt{2}-\pi_1*b_3"
and I should get
- 5a^3
- \sqrt{3}-\sqrt{2}
- \pi_1*b_3
(These are just expressions, NO mathematics involved, I know what I am trying to get.)