in reply to Re: Howto strip 42 from comma separated list using s///
in thread Howto strip 42 from comma separated list using s///

s/(,42|42,|\b42\b)//g;
Tricky, isn't? Unfortunally, you still haven't cover all cases correctly:
$ perl -wle '$_ = "142,143"; s/(,42|42,|\b42\b)//g; print' 1143
You need to anchor all cases:
s/,42\b|\b42,|^42$//; # Or s/\b(?:,42|42,|42)\b//; # Or s/\b42,|,?42\b//;
Perl --((8:>*

Replies are listed 'Best First'.
Re^3: Howto strip 42 from comma separated list using s///
by jbware (Chaplain) on Nov 03, 2005 at 14:21 UTC
    Yeah, and painful. Although it can be done it regex, it just goes to show why I would much rather iterate through a list and process each element individually instead of handling all the element special cases in a regex. From a processing efficiency standpoint I'm not sure which is better, but I think regarding a programmer's efficiency, and future understanding, I'd lean toward looping through a list and handling each element on its own as a better decision. It just seems cleaner to me (as fun as regex exercises are); but maybe that's just me.

    -jbWare