1

I've tested this regex:

String regex = "[e][#](.)+[$]

the regex works well to identify exponential terms, however it breaks when there are two or more consecutive exponential terms.

I test the regex with the usual code:

while(matcher.find()){
String string = matcher.group();
System.out.println("this one: "+string);
}

When I type the expression:

e#x$ + 3e#x+1$

string equals to (e#(x$+3e#x+1$))

By the way, I added the parentheses inside the while loop. They are necessary for what I am trying to accomplish.

I want the result of string to be (e(#x$))+3(e(#x+1$)

I know the problem lies in "(.)+ What I think is happening is that the regex includes the first $, what I need is for it to stop at the first $.

How can I include this logic inside the regex?

thank you

i_o
  • 777
  • 9
  • 25

0 Answers0