hi again
i've been trying different things and it seems that the [^0] or [^\d]
is stopping it working. (I needed to use $1 rather than \1 to
reference the first group in the String.replace statement)
here is what i've got so far
var sYear:String = "1234567";
var pattern:RegExp = /(\d\d\d)(?=(?:\d\d\d)*[^\d])/g;
sYear = sYear.replace(pattern, ",$1");
//traces 1234567
if i drop the NOT part
var sYear:String = "1234567";
var pattern:RegExp = /(\d\d\d)(?=(?:\d\d\d)*)/g;
sYear = sYear.replace(pattern, ",$1");
//traces ,123,4567
This stuff is really new to me so i really appreciate the help
thanks
a
On 4 Jul 2008, at 01:09, Claudius Ceteras wrote:
Hi,
is there a way of counting back from the end of the number and
inserting the comma (even without a regular expression)? if i
use the
g modifier in the regexp (so var pattern:RegExp = /000/g;), it will
only pick up the first 000 (and every multiple thereafter)
instead of
leaving the first 0 (which is expected behaviour but something i'd
like to get around)
How about positive lookaheads?
/(000)(?=(?:000)*[^0])/g
If you want this also to work for "1234567" => "1,234,567", you can
replace
every 0 in the pattern with \d and call the replace function with ",
\1"
instead of ",000"
This is untested, but should work... Let me know.
regards,
Claudius
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders