George_Sherston has asked for the wisdom of the Perl Monks concerning the following question:
I'm struggling to understand this. The purpose of the regex is to place commas before every third digit (counting backwards) - i.e. to format them nicely. And indeed, it does do this! But how?1 while s/(\d)(\d\d\d)(?!\d)/$1,$2)/;
then I'd understand what was going on - we're just saving time by not capturing the third cluster. But then the regex doesn't work. Another way to do it is1 while s/(\d)(\d\d\d)(?:\d)/$1,$2)/;
Which does work, and in a way I understand. But what I still don't get is this ?! business. I can't find anything in the Camel to explain it. Is it negation? But then why? And why doesn't1 while s/(\d)(\d\d\d)(?:,|$)/$1,$2/;
work?1 while s/(\d)(\d\d\d)(?:\D)/$1,$2/;
Edit: Changed title, on author's request. larsen
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: ?! idiom in regex - que?
by broquaint (Abbot) on Jun 05, 2002 at 11:15 UTC | |
|
Re: code(?!/code idiom in regex - que?
by marvell (Pilgrim) on Jun 05, 2002 at 11:23 UTC |