((?=,*\s*42))(,\s*42|42\s*,|\s*42\s*)((?<=42\s*,*))Being left with a result, which is not applicable in Perl isn't satisfying either. (There is no variable length lookbehind in Perl.)
I tried to understand your regex without being able to test it (as given) in Perl. But I either did not get it, or it is still incomplete, as I have the impression, that a string like before,42XX,after will be reduced to beforeXX,after after applying your regex and substituting the match to empty??
Anyway, I would suggest to use the regex provided by reasonablekeith earlier, because it seems to cover all cases correctly.
Stripping enclosing whitespace is easily achieved with this too, by adjusting 42 to \s*42\s* (twice) in that regex.
In reply to Re^2: Howto strip 42 from comma separated list using s///
by pKai
in thread Howto strip 42 from comma separated list using s///
by ady
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |