rhymejerky has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have a string that looks like this '2,7,3,4,5,1,7', my goal is to remove 4 and 7 from that string to get 2,3,5,1. I have tried using regexp /(4[,]*|7[,]*)// but left with a trailing ',' what would be a good way to remove that without doing 2 regexp? Thanks,

Replies are listed 'Best First'.
Re: reg exp on number string
by Fletch (Bishop) on May 28, 2009 at 21:20 UTC

    Smells like an XY Problem, but join(",", grep !/^(?:4|7)$/, split( /,/, "2,7,3,4,5,1,7" ) ) comes to mind.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: reg exp on number string
by ikegami (Patriarch) on May 28, 2009 at 21:45 UTC