Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Still having trouble with regexes! Please help

by AnomalousMonk (Archbishop)
on Jan 31, 2016 at 05:45 UTC ( [id://1154103]=note: print w/replies, xml ) Need Help??


in reply to Still having trouble with regexes! Please help

Update: The approach discussed in this reply has a problem. Don't use it. For a fix, see my reply below.

This needs the Perl version 5.10 regex extensions and defined-or operator, the latter not critical. This approach needs extensive testing to be trusted. (Update: Some more testing done with the test cases used by choroba in his reply in your other thread gives me a bit more confidence in this approach, but you must still thoroughly test!)

c:\@Work\Perl\monks>perl -wMstrict -le "use 5.010; ;; my $x = q{((A & B)' | (A & C & (A & B & D | (A & (B' & D)')'))}; print qq{:$x:}; ;; my $parenthetic = qr{ ( [(] (?: [^()]*+ | (?R))* [)] ) }xms; my $term = qr{ ( [[:alpha:]] \w* ) }xms; ;; 1 while $x =~ s{ (?: $parenthetic | $term) \x27 }{ '!' . ($1 // $2) } +xmsge; print qq{:$x:}; " :((A & B)' | (A & C & (A & B & D | (A & (B' & D)')')): :(!(A & B) | (A & C & (A & B & D | !(A & !(!B & D)))):
(Note that my REPL does not like unbalanced single-quote characters, so I use  \x27 instead of a single single-quote at one point.) There is probably a more elegant way to express and use these regexes, but it's late...

Update 1:

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))))
I assume that the single-quote after the  !(A & B)' term as quoted from the OP should not be there. If so, please update the OP.

Update 2:

my $x ='((A & B)\' | (A & C & (A & B & D | (A & (B\' & D)\')\'))';
Do yourself a favor and choose a different delimiter when the delimiter character appears in the delimited string:
    my $x = q{((A & B)' | (A & C & (A & B & D | (A & (B' & D)')'))};


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1154103]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-20 04:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found