Learning_Perl_2017 has asked for the wisdom of the Perl Monks concerning the following question:
We still seem to have trouble getting the regex to work correctly!
Here is the original expression:
my $x ='((A & B)\' | (A & C & (A & B & D | (A & (B\' & D)\')\'))';
From the original value of $x printed above, we have to create the following slightly modified expression, like below:
(!(A & B) | (A & C & (A & B & D | !(A & !(!B & D))))
Our Perl program looks like this right now:
#!/usr/bin/perl use strict; use warnings; my $x = '((A & B)\' | (A & C & (A & B & D | (A & (B\' & D)\')\'))'; print "Given: $x\n"; $x =~ s/(\(\s*[^()]+\s*\))\'/\!$1/g; print "Calculated: ",$x,"\n"; $x =~s/([a-zA-Z]\w*)\'/\!$1/g; $x =~ s/((\(){1}\s*.*?([!][(])+.*?\)\s*)\'/\!$1/g; print "NewVl : ",$x,"\n";
I think we have to get it right on how to handle the nested ' single code character (BTW, ' is for representing negation of a value or a logical expression in one tool and we are trying to replace that single quote character to ! character, which is needed in another tool, and print it like stated above).
Thanks for the continued huge help. Bill
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Still having trouble with regexes! Please help
by AnomalousMonk (Archbishop) on Jan 31, 2016 at 08:25 UTC | |
|
Re: Still having trouble with regexes! Please help
by choroba (Cardinal) on Jan 31, 2016 at 14:48 UTC | |
|
Re: Still having trouble with regexes! Please help
by AnomalousMonk (Archbishop) on Jan 31, 2016 at 05:45 UTC | |
|
Re: Still having trouble with regexes! Please help
by AnomalousMonk (Archbishop) on Jan 31, 2016 at 06:16 UTC |