in reply to Regex matching and substitution

G'day Bill,

Welcome to the Monastery.

You're almost there. Just change the '.' in your regex to '[^(]'. Here's your code with that change (plus a small modification to the shebang line for my purposes):

#!/usr/bin/env perl use strict; use warnings; my $x = '((A & B)\' | (A & C & (A & B & D)\'))'; print "Given: $x\n"; #$x =~ s/(\(.*?\))\'/\!$1/g; $x =~ s/(\([^(]*?\))\'/\!$1/g; print "Calculated: ",$x,"\n";

Output:

Given: ((A & B)' | (A & C & (A & B & D)')) Calculated: (!(A & B) | (A & C & !(A & B & D)))

— Ken