regex - JavaScript or Notepad++ regular expression to add thousands separator to arbitrary text -
as part of visualisation, i'd add thousands separators numbers (contiguous string of digits) in string. needn't consider context of number e.g.
1234e+56789 nokia 3210s cost $123456.7890 , phone number 123-4567-89012. becomes
1,234e+56,789 nokia 3,210s cost $123,456.7,890 , phone number 123-4,567-89,012. i know can reverse string, replace \d{3}(?=\d) $&, , reverse again, there way regular expressions (preferably one)?
it's pretty same attempt, reversed , quantifier:
\d(?=(?:\d{3})+(?!\d)) and replace $&,.
the (?:\d{3})+ makes sure there multiple of 3 digits following , (?!\d) makes sure there no fourth or fifth digit following.
if want use in notepad++ make sure upgrade version 6.
note in notepad++ use lookbehind:
(?<=\d)(?=(?:\d{3})+(?!\d)) and replace ,.
Comments
Post a Comment