in reply to Re: A regex question
in thread A regex question
s/(?<=^| )blah(?= |$)/something/g;
I may be wrong but I thought look-behinds were fixed-width so the following gives a compilation error.
$ perl -le ' > $str = q{adfsdheHjdGafefaffJaff}; > $str =~ s{(?<=^|[A-Z])a}{999}g; > print $str;' Variable length lookbehind not implemented in regex; marked by <-- HER +E in m/(?<=^|[A-Z])a <-- HERE / at -e line 3. $
You could use an alternation of two look-behinds.
$ perl -le ' > $str = q{adfsdheHjdGafefaffJaff}; > $str =~ s{(?:(?<=^)|(?<=[A-Z]))a}{999}g; > print $str;' 999dfsdheHjdG999fefaffJ999ff $
I hope this is of interest.
Cheers,
JohnGG
|
|---|