I would like to match single negated letters in some function and replace with “NANAD-neg_letters”. single negated letter means this letter is the only one between ++
Examples:
F=**A**'+**B**' => NAND-**A**+ **B**
F=**A**'+**B**'+A'B' => A'B'+NAND-**A**+ **B**
F=**A**'+**B**'+A'B =>A'B+NAND-**A**+ **B**
F=*A*'+B+*C*'=>B+NAND-**A**+ **C**
F=AB+*A*'+B+*C*'+D+ABC=>AB+B+D+ABC+NAND-**A**+ **C**
I wrote the following test in Java, but it works only for the first example:
public class Test {
public static void main (String[] args) {
String test="A'+K+D'";
System.out.println (test.replaceAll ("([A-Z])'\\+([A-Z])'([\\+[A-Z]'])?([\\+[A-Z]'])?", "NAND-$1\\+$2$3$4") .replace ("'", ""));
}
}
Any Idea?
This is one of those cases where a regex isn’t the right tool. You need a parser.