Rewriting parts of a string
I have a string I would like to rewrite. The string contains substrings
that look like "DDT" plus four digits. I'll call these blocks. It also
contains connectives like "&" and "|", where | represents "or", as well as
parentheses.
Now I would like to rewrite this string such that blocks separated by &s
should be written as "min(x(block1), x(block2), etc.)", whereas blocks
separated by |s should be written as "max(x(block1), x(block2), etc.)".
Looking at an example should help:
public class test{
public static void main(String[] arg) throws Exception {
String str = "(DDT1453 & DDT1454) | (DDT3524 & DDT3523 & DDT3522 & DDT3520)";
System.out.println(str.replaceAll("DDT\\d+","x($0)"));
}
}
My desired output is:
max(min(x(DDT1453),x(DDT1454)),min(x(DDT3524),x(DDT3523),x(DDT3522),x(DDT3520)))
As you can see, I performed an initial substitution to include the
x(block) part of the output, but I cannot get the rest. Any ideas on how
to achieve my desired output?
No comments:
Post a Comment