I am new to regular expressions. I am testing an iterative regular expression. For the first time it works but second time pattern isn't initializing again.
Here is my code:
public static void main(String a[])
{
String s="1+2+4*5*tan(tan(30))-5.8+tan(30)";
Pattern p;
Matcher m;
while(s.contains("tan("))
{
double[] x=new double [5];
p=Pattern.compile("tan\\([0-9]+\\)");
m=p.matcher(s);
int i=0;
while(m.find())
{
System.out.println(m.group());
x[i]=Math.tan(Math.toRadians(Double.parseDouble(m.group().replace("tan(","").replace(")",""))));
i++;
}
for(int z=0;z<i;z++)
{
s=s.replaceFirst("tan\\([0-9]+\\)",""+x[z]);
}
}
System.out.println(s);
}