if the number is 7 digits longs it doesnt add the comma
The reason is because you anchor your match to the end of the line with $. Your regex is doing exactly what you're asking it to do: match 4 digits at the end of the string, and insert a comma in the appropriate place.
It's messy to write a "normal" regex to do what you want, because regular expressions scan your string from left to right. The easiest way commafy a number is to actually reverse the string first, as demonstrated by borisz's earlier post.
In reply to Re: simple regex
by revdiablo
in thread simple regex
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |