We have complicated expressions like this, which may also contain deep nesting:
((A & B)' | (A & C & (A & B & D)'));
Every time we see sub expressions like:
(1) (A & B)\' and
(2) (A & C & (A & B & D)')
we have to substitute them with the following:
!(A & B) for (1) above
and (A & C & !(A & B & D)) for (2) above.
I wrote the following but it obviously requires some more improvements. Can you help me know what I am doing wrong?
#!/usr/bin/perl use strict; use warnings; my $x = '((A & B)\' | (A & C & (A & B & D)\'))'; print "Given: $x\n"; $x =~ s/(\(.*?\))\'/\!$1/g; print "Calculated: ",$x,"\n";
That prints:
Given: ((A & B)' | (A & C & (A & B & D)')) Calculated: (!(A & B) | !(A & C & (A & B & D)))
The second part of the sub expression is incorrect as my regex match did not do what is intended, which is: substitute (A & B & D)' with !(A & C & (A & B & D))
Thank you friends.
Bill Murphy.
In reply to Regex matching and substitution by Learning_Perl_2017
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |