in reply to reg exp on number string

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.