As a disclaimer, I'm in the middle of reading Mastering Regular
Expressions[0], so my head isn't in the right place. None of these solutions
should be used in production code ever, probably.

Assuming something like 1,000,000,000,123,212,888,546,248 is in $_,

Using only a match, no substitution:
say join '', /(?:\b(\d+)\K)?,(\d{3})/g;

Using the /r switch, so this should only work for fairly modern Perls
s/(\d+(?:,\d{3})*)/ $1 =~ tr!,!!rd /e;
say;

Without capturing groups,
/\d+(?:,\d{3})*/;
substr($_, $-[0], $+[0] - $-[0]) =~ tr/,//d;
say;

And here's what I would actually be using:
s/ (?<=\d) , (?=\d{3}) //xg;
say;

Brian.

[0] http://regex.info/

Reply via email to