in reply to Appending strings
Perhaps you could use positive and negative look-arounds with pos to find where you want to insert $path. and then work back along the string inserting with the 4-argument form of substr.
use strict; use warnings; use 5.014; my $path = q{XX.YY.ZZ}; my $str = q{(ABC | (~dEf & hI_J)) & ~LMn if ~xYz}; # Make a compiled regex of an alternation of the terms to exclude. # my $rxExcl = do { my @excl = qw{ if else 1'b0 }; local $" = q{|}; qr{(?:@excl)}; }; my @posns; push @posns, pos $str while $str =~ m{(?x) # Use extended regex syntax (?<! [A-Za-z_] ) # Match at a point not preceded by # letters or underscore (?= [A-Za-z_] ) # And which is followed by letters # or underscore (?! $rxExcl ) # But not followed by any our terms # to exclude }g; substr $str, $_, 0, qq{$path.} for reverse @posns; say $str;
Outputs
(XX.YY.ZZ.ABC | (~XX.YY.ZZ.dEf & XX.YY.ZZ.hI_J)) & ~XX.YY.ZZ.LMn if ~X +X.YY.ZZ.xYz
I hope this is useful.
Update: Added comment above $rxExcl creation and comments to the string matching regex to clarify what it is doing.
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Appending strings
by doofus (Acolyte) on Mar 11, 2016 at 22:15 UTC | |
by johngg (Canon) on Mar 11, 2016 at 22:46 UTC | |
by doofus (Acolyte) on Mar 11, 2016 at 23:50 UTC | |
by AnomalousMonk (Archbishop) on Mar 12, 2016 at 03:34 UTC |